I ran into a problem today that had me scratching my head for a bit. Suppose you have a large flash project that loads a number of external SWFs. Suppose furthermore that several of those SWFs, as part of their default behavior, instantiate display objects from within their own libraries. Let’s get more specific.
Take this example. Map.swf has a symbol in its library (a Bitmap) exported as “MarkIcon.” If in the constructor I add the following code…
public function Map() {
addChild(new Bitmap(new MarkIcon(50, 50)));
}
…my SWF has no problem correctly displaying its image. Pardon the awful graphics. This is for demonstration purposes only.
What happens when I later try to load this simple SWF into another SWF?
We get a compilation error of course. This sounds like a big problem, doesn’t it? What could we possibly do to fix this? We instantiate via the child SWFs applicationDomain property. Huh?
public function Map() {
var miDef:Class = this.loaderInfo.applicationDomain.getDefinition("MarkIcon") as Class;
addChild(new Bitmap(new miDef(50, 50) ));
}
Now it works everywhere. This same technique can also be used to instantiate the class from within the parent SWF. How’s that for fancy?




















About AgitCraft