With Actionscript, you can load external .swf files into your current movie. This allows you to load movies into movies (or load content on demand). It's also possible to load content from the library to the stage, which is the approach you may take using HTML5/JS.
Movie to Movie (or Movieclip to Movieclip) - AS2
To load a movie into a movieclip (using a local path)
on (release) {
nameOfMovieClip.loadMovie("FileToLoad.swf");
}
To load a movie into a movieclip (using a local path to a folder and then the file)
on (release) {
nameOfMovieClip.loadMovie("MyFolderName/FileToLoad.swf");
}
To load a movie into a nested movieclip (using an absolute path)
on (release) {
_root.mc1.mc2.loadMovie("FileToLoad.swf");
}
To replace the entire movie with a new movie (replace the root level/layer)
on (release) {
loadMovieNum("FileToLoad.swf", 0);
}
To add a new movie on top of your current movie (into a level/layer on top)
on (release) {
loadMovieNum("FileToLoad.swf", 1);
}
Movie to Movie (or Movieclip to Movieclip) - AS3
stop();
var myContentLoader:Loader = new Loader();
var myContentURL:URLRequest = new URLRequest("sectionone.swf");
loadbox.addChild(myContentLoader);
//note "loadbox" is the instance name of the movieclip on the stage to load into
myContentLoader.load(myContentURL);
section1_btn.addEventListener(MouseEvent.CLICK, onClick);
section2_btn.addEventListener(MouseEvent.CLICK, onClick2);
function onClick(e:MouseEvent) {
myContentURL = new URLRequest("sectionone.swf");
myContentLoader.load(myContentURL);
}
function onClick2(e:MouseEvent) {
myContentURL = new URLRequest("sectiontwo.swf");
myContentLoader.load(myContentURL);
}
Movie to Movie - HTML5/JS
With HTML5/JS, you cannot load external .swf files, but you can load movieclips from the library and add them to the stage.
//Set the "linkage" property of the symbol in the library first
//In this case, the "linkage" is named "clipLinkageName"
var myInstanceName = new lib.clipLinkageName();
this.button.addEventListener("click", onClick.bind(this));
function onClick() {
//add the symbol to the stage
this.addChild(myInstanceName);
//position the x,y coordinates of the symbol on the stage
myInstanceName.x = 200;
myInstanceName.y = 100;
}
this.button2.addEventListener("click", onClick2.bind(this));
function onClick2() {
//remove the symbol from the stage
this.removeChild(myInstanceName);
}