miguel.hpsgaming
miguel.hpsgaming

Reputation: 481

AS3 load symbol from external swf library

I have 2 SWF, one of them (let's call it Resources.swf), that contains several symbols (most of them MovieClips) on its library, but, none of them are added into the stage ( the timeline contains only one empty frame), and then, the other swf (Main.swf), where I need to import some of the symbols from the other SWF.

I have been looking around, and searching, but all the info that I saw, and tried, imports the symbols from the stage/timeline using things like:

loadedMC = MovieClip(loader.content);

or

loadedMC = MovieClip(event.target.content);

My symbols have a class definition, because, they are also used in other swf this way:

[Embed(source='assets/Resources.swf', symbol='SymbolName')]
public class Generic2 extends MovieClip

Is there any way to do this?

If not,do I have modify my Resources.swf to work this out or do I have other alternatives?

Upvotes: 1

Views: 6653

Answers (3)

milkplus
milkplus

Reputation: 34247

Follow these steps

  1. In flash, mark your class for export by bringing up "Properties" for the library item and checking "Export for ActionScript" and giving it a "Class" name.
  2. Publish Resources.SWF
  3. After loading Resources.SWF, you can create instances with this helper function
  4. You can then addChild() or whatever you want with the instance.

Helper Function

public function createInstance(mc:MovieClip, className:String, instName:String):MovieClip
{
    var cls:Class = mc.loaderInfo.applicationDomain.getDefinition(className) as Class;
    if (cls)
    {
        var instMC:MovieClip = new cls();
        instMC.name = instName;
        return instMC;
    }
    return null;
}

Upvotes: 2

BenoitIT
BenoitIT

Reputation: 1

You need to have a as3 class, or just to export the symbol in the frame otherwise you can't reference it. Your swf will be empty if you don't export your movieclip... Basically you can just export it as a Certain class and then reference the empty class!

Upvotes: 0

DanielB
DanielB

Reputation: 20210

After loading the Resources.swf you can create instances of the loaded classes.

Here a snippet that may help:

var dynClass : Class = Class(getDefinitionByName("fully.qualified.ClassName"));
if(dynClass) 
{
    var app : Object = new dynClass();
    addChild(app as DisplayObject);
}

Upvotes: 2

Related Questions