Skip to main content
Inspiring
April 9, 2013
Question

load external swf into existing mc

  • April 9, 2013
  • 1 reply
  • 1554 views

I think this is very old question,

in as2 you can just add a external swf inside a mc.  like this -  loadMovie ("example.swf", "_root.mc");  and that's it.

how do i do that in as3? this following doesn't work..

var newLoader:Loader = new Loader();

function loadMc(evt:MouseEvent) {

    var request:URLRequest = new URLRequest("example.swf");

    newLoader.load(request);

    addChild(mc.newLoader);

}

can I go remove mc first, and then add the swf as mc again?

removeChild(mc);

addChild(mc);

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 10, 2013

there's generally no reason to do that but, you can:

var newLoader:Loader = new Loader();

function loadMc(evt:MouseEvent) {

    var request:URLRequest = new URLRequest("example.swf");

    newLoader.load(request);

    mc.addChild(newLoader);

}

Inspiring
April 10, 2013

Hi Kglad,

my 'mc' has another clip 'mc1' in it. so i tried to remove mc1 after loaded example.swf

I did try these method

#1

var newLoader:Loader = new Loader();

function loadMc(evt:MouseEvent) {

    var request:URLRequest = new URLRequest("example.swf");

    newLoader.load(request);

    mc.addChild(newLoader);

     mc.removeChild(mc1); <--

}

#2

var newLoader:Loader = new Loader();

function loadMc(evt:MouseEvent) {

     var target = mc.mc1;

    var request:URLRequest = new URLRequest("example.swf");

    newLoader.load(request);

    mc.addChild(newLoader);

     removeChild(target); <--

}

both don't work, example.swf is added, but can't get rid of the original mc

you know in as2, when I call 'loadMovie ("example.swf", "_root.mc");', example.swf will just replace mc.

Inspiring
April 10, 2013

Look here how loading in AS3 works.

Important: You must always wait until your swf is fully loaded until you do any DisplayListManipulations (adding or emoving childs, accessing stage, root or parent) with it.

Use Event.COMPLETE for that.

Then move your lines

    mc.addChild(newLoader);

     mc.removeChild(mc1);

inside that Handler-function