Papervision3D: Accessing dynamic content within a MovieAssetMaterial
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.
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
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();
var itemPath = [path];
Thanks to Ryan Robinson of Infinite Array for providing the majority of this solution.