Papervision3D: Accessing dynamic content within a MovieAssetMaterial

Papervision3D: Accessing dynamic content within a MovieAssetMaterial

July 6, 2010 in Blog, Interaction Design

Whilst developing a 3D timeline in Flash and Papervision3D for a client, I came across a problem which took me almost a week to fix. There was no single solution to this problem on the web, so I thought I’d post a consolidated example here to save other Flash/PV3 devs some time.

PV3′s MovieAssetMaterial class allows you to apply a library asset as a material, complete with any interactivity the asset contains. However, dynamic items within an asset (dynamic text fields, movieclips, etc.) are not directly accessible from the main AS3 class, as the property type of items within the MovieAssetMaterial is defined as DisplayObject rather than MovieClip or Sprite and are therefore not visible to AS3 using standard reference notation.  I was able to solve this problem by creating variables which store the paths to the movie asset’s dynamic items and then referencing the dynamic items through these variables. Here are some examples:

var myMaterial:MovieAssetMaterial = new MovieAssetMaterial("[library asset name]", true, false, false, true) // Set the library asset as a MovieAssetMaterial in PV3D
var myClip = MovieClip(myMaterial.movie); // create a variable to store the path to the asset

// Add text to a dynamic text field within the asset
var myText = myClip.getChildByName("[text field name]");
myText.text = "Here's my text";

// Load something into an empty clip within the asset
var myItem = myClip.getChildByName("[dropbox Label_mc]");
var myLoader:Loader = new Loader();
myItem.addChildAt(myLoader,myItem);
var itemPath = [path];
myLoader.load(new URLRequest(itemName));

Thanks to Ryan Robinson of Infinite Array for providing the majority of this solution.

Copyright © 2009 Rational Systems - Powered by WordPress.