0

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?

Ivan Chaer
  • 6,980
  • 1
  • 38
  • 48
beans
  • 1,765
  • 5
  • 25
  • 31

2 Answers2

2

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);
Daniel
  • 34,125
  • 17
  • 102
  • 150
  • 1
    on the new FB 4.7 I think you will need to add a slash at the beginning ("/assets/yourswif.swf") to prevent errors. Also make sure that you don t use relative paths like ../.. – mika May 09 '13 at 17:32
-1

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

N Rohler
  • 4,595
  • 24
  • 20