Skip to main content
Made By Things
Known Participant
December 13, 2010
Answered

Embedding swf in container on page load

  • December 13, 2010
  • 1 reply
  • 1806 views

I'm trying to figure out what the AS3 script is to have a swf embedded inside of a container, little new to AS3. any help? Thanks.

This topic has been closed for replies.
Correct answer Ned Murphy

There is nothing wrong with that code unless you have some object on the stage with the instance name "sliderCont" that you are expecting to have the swf load into.  The code creates a loader instance named "sliderCont" and loads an swf into it, and then adds that loader to the display list.

If "sliderCont" is some other object, then you need to pick a different name for your loader and then add the loader as a child of that.

var ldr:Loader = new Loader();
ldr.load(new URLRequest("flash-xml3.swf"));
sliderCont.addChild(ldr);

1 reply

Ned Murphy
Legend
December 13, 2010

Use the Loader class to load the file and add the loader as a child to whatever container you intend.

Made By Things
Known Participant
December 13, 2010

Alright, I looked into the loader class as you said and I still can't seem to get it to work. Here's what I have so far..It might be completely wrong, but hopefully you can help me out again.

var sliderCont:Loader = new Loader(); sliderCont.load(new URLRequest("flash-xml3.swf")); addChild(sliderCont);

sliderCont is the container i'd like the .swf to play

Thanks!

Ned Murphy
Ned MurphyCorrect answer
Legend
December 13, 2010

There is nothing wrong with that code unless you have some object on the stage with the instance name "sliderCont" that you are expecting to have the swf load into.  The code creates a loader instance named "sliderCont" and loads an swf into it, and then adds that loader to the display list.

If "sliderCont" is some other object, then you need to pick a different name for your loader and then add the loader as a child of that.

var ldr:Loader = new Loader();
ldr.load(new URLRequest("flash-xml3.swf"));
sliderCont.addChild(ldr);