Skip to main content
Inspiring
June 30, 2013
Question

Load and unload the external swf file using AS3(for window, IOS and android)

  • June 30, 2013
  • 1 reply
  • 17553 views

For the external swf file loading, I use this code

-----------------------------------------------------------------------------------

load2.addEventListener(MouseEvent.MOUSE_DOWN, newvid);

function newvid(event:MouseEvent) {

          trace("you clicked me");

          var loadit = new Loader();

          addChild(loadit);

    var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);

    loadit.load(new URLRequest("scene02.swf"), _lc);

}

------------------------------------------------------------------------------------

its working great but I don’t know how to unload the loaded swf files (looking: unload one by one and unload all)

_______________________________________________________________

in AS2 we have

on (release) {

          loadMovieNum("scene2.swf", 1);

          unloadMovieNum(2);

          unloadMovieNum(3);

}

but i need in AS3

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
June 30, 2013

You need some way of targeting the Loader object so that you can use its unloadAndStop() method.  But because you declare the Loader inside the function, you have nothing to reference it with when you are outside the function.  So you need to have some external reference available to directly target the Loader, which could be as simple as a variable, or actually declare the Loader outside, or if there will me a number of themyou can use an array.

71081Author
Inspiring
June 30, 2013

can you tell me how

Ned Murphy
Legend
June 30, 2013

For the one Loader you can declare it outside the function so that it is available outside the function when you need to target it

var loadit:Loader; // loader is declared outside the function

load2.addEventListener(MouseEvent.MOUSE_DOWN, newvid);

function newvid(event:MouseEvent) {

          trace("you clicked me");

         loadit = new Loader();  // here it is instantiated

          addChild(loadit);

          var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);

          loadit.load(new URLRequest("scene02.swf"), _lc);

}

//later on somewhere in some other function....

function.... etc {

          loadit.unloadAndStop(); // Loader content is removed

}