Case 2: Familiarity with the use of addchild and removechild between different SWF, and loader usage
Description: Click on the picture to load another SWF, click on the loaded SWF on a button, the SWF disappears.
Demo: http://www.live-my-life-with-yuyi.com/as3_cases/different_movies/
Code:
SWFA (which is the flash where the button is)
Copy Code code as follows:
var loader:loader = new Loader ();
Loader.load (New URLRequest ("popup.swf"));
Picture_btn.addeventlistener (Mouseevent.click, showpicture);
function Showpicture (event:mouseevent): void
{
AddChild (loader);
}
AS3 loader instead of loadmovie,load, you can't add the path name directly, you need to load it through urlrequest.
The whole piece of code is very simple, first load popup.swf, and then give the Listener button click event to define a showpicture function, the function is very simple, through the addchild of the SWF just loaded onto the stage.
SWFB (Loaded flash->popup.swf)
Copy Code code as follows:
Close_btn.addeventlistener (Mouseevent.click, CloseWindow);
function CloseWindow (event:mouseevent): void
{
This.parent.parent.removeChild (this.parent);
}
Very concise, listening to the click of the Close button event, when the event is triggered call the CloseWindow function, here with the parent, a simple analysis, as this SWF has been loaded into another SWF, So this.parent should refer to the loader, and this.parent.parent refers to the TimeLine0, that is, the stage. So this sentence is better understood: remove the loader from the stage loading the SWF.
This concludes the case 2 analysis.
Package file Download