I embed an external swf in flash builder like so:
[Embed(source="assets/sounds/mytestswf.swf")]
private static var mySwf: Class;
How can I access it and add it to another sprite on stage?
I embed an external swf in flash builder like so:
[Embed(source="assets/sounds/mytestswf.swf")]
private static var mySwf: Class;
How can I access it and add it to another sprite on stage?
i don't think you need a loader, that's for libraries that are added at runtime. Embed compiles the assets directly in the swf, so addChild(new mySwf());
is enough to add it to the the display object list.
obviously, you'd like to assign it to a variable, so
var $mySwf:mySwf = new mySwf();
addChild($mySwf);
On a side note, you should name your classes consistently. Class names start with the first letter capitalized, so you can tell it apart from variables
[Embed(source="/assets/sounds/mytestswf.swf")]
private static var MySwf: Class;
...
var $mySwf:MySwf = new MySwf();
addChild($mySwf);
First, you need to specify mimeType="application/octet-stream"
on your Embed
. Then, you need to create a Loader
instance and use the Loader.loadBytes()
method to load the ByteArray
associated with the embedded class:
var bytes:ByteArray = new mySwf();
var loader:Loader = new Loader();
loader.loadBytes(bytes);
addChild(loader);
Reference for learning: Loader.loadBytes() method