I’ve been trying to find an elegant way to display MovieClip symbols from a Flash 9 swf in a Flex app. I am rewriting my old game ChipWits (google it) and have a bunch of graphics which I need to repeat for walls, floors… All the graphics are in Symbols with auto-generated classes (coffee class for the coffee symbol).
I have it working in a very inelegant manner by putting named instances of each of the Symbols on the stage. In Flex I call a function in the swf’s Document class that moves the symbol to 0,0 and makes it visible in the swf:
private var mc_Item:MovieClip = null;
public function showInstanceInSWF(itemName:String):void {
// If it has the property draw it
if( this.hasOwnProperty(itemName) ) {
// Get rid of any old instance in the SWF
if(this.mc_Item != null) {
this.mc_Item.visible = false;
this.mc_Item = null;
}
// Point mc_Item to the MovieClip on stage named itemName
this.mc_Item = this[itemName];
if(this.mc_Item != null) {
this.mc_Item.x = 0;
this.mc_Item.y = 0;
this.mc_Item.alpha = 100; // They are alpha=0 in Flash
this.mc_Item.visible = true;
}
}
}
This means that for every piece of floor, wall, etc. onstage I need to load another SWF.
What I’d like to do is something like:
public function returnSymbolFromClass( className:String ):MovieClip {
var mc:Object = null;
try {
var ClassReference:Class = getDefinitionByName(className) as Class;
mc = new ClassReference();
}
catch(e:ReferenceError) {
trace(e);
}
return MovieClip(mc);
}
and then to take the MovieClip and addChild it in my app outside the loaded SWF.
This has me pulling my hair out. I am breaking my swf’s up so there is one symbol in each, but again this is very kludgy.
Any help will be grovellingly appreciated.