Skip to main content
Inspiring
March 5, 2015
Answered

load external swf onto an mc that is on screen

  • March 5, 2015
  • 1 reply
  • 352 views

this seems like a basic question but if I have an swf file in the same directory as the fla, and want to have it on an mc, is there a simple way? so I pull an movieclip on the screen and want it to load. anyone have a quick example?

This topic has been closed for replies.
Correct answer kglad

use the loader class to load an external swf.

var loader:Loader=new Loader();

loader.load(new URLRequest("yourexternalswf.swf"));

addChild(loader);  // adds the loader to the current timeline

// if you want to add the loader to a movieclip, apply the addChild method to that movieclip, eg:

yourmovieclip.addChild(loader);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 5, 2015

use the loader class to load an external swf.

var loader:Loader=new Loader();

loader.load(new URLRequest("yourexternalswf.swf"));

addChild(loader);  // adds the loader to the current timeline

// if you want to add the loader to a movieclip, apply the addChild method to that movieclip, eg:

yourmovieclip.addChild(loader);

Inspiring
March 5, 2015

so would i put this code in the main as3 timeline or in the code of the appeared movieclip?

i put this in the main area like this (in the click of a button function)

function CFbandELEVENbutton(e: MouseEvent): void

{

  TweenMax.to(CFbandELEVENevalbox, 0.5, {alpha:1});

  CFbandELEVENevalbox.visible=true;

  CFbandELEVENevalbox.mouseEnabled=true;

  var loader:Loader=new Loader();

  loader.load(new URLRequest("eval.swf"));

  addChild(loader);  // adds the loader to the current timeline

// if you want to add the loader to a movieclip, apply the addChild method to that movieclip, eg:

CFbandELEVENevalbox.addChild(loader);

}

this returns an error

Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed.

kglad
Community Expert
Community Expert
March 5, 2015

you wouldn't use both these:

  addChild(loader);  // adds the loader to the current timeline

CFbandELEVENevalbox.addChild(loader);

either add to the current timeline or some other parent like CFbandELEVENevalbox

and that error is caused because eval.swf is not found in the default directory.