Reputation: 1253
In a flash project, I am loading an external SWF that has some symbols in its library exported for ActionScript. I need to create instances of those symbols but, since it's a loaded SWF I don't have direct access to that classes.
Any ideas?
Upvotes: 0
Views: 854
Reputation: 2220
Well, there are several ways of doing this.
The nicest could be this:
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener("complete", ldrDone);
ldr.load(new URLRequest("external.swf"));
function ldrDone(evt:*):void
{
var externalclass:Class = evt.target.applicationDomain.getDefinition("ExternalClass") as Class;
var temp:MovieClip = new externalclass();
addChild(temp);
}
Where ExternalClass
is the exported classname in the external swf.
Or, simply use a function in your external movie, where you return the specific objects on demand.
Like put this in your external swf:
function getThisClass():*
{
return new MyClass();
}
This is not that awesome as the first one, but could lead to other ideas too.
Hope this helps.
Upvotes: 5