AS3.0 instance learning is familiar with the use of addchild and removechild between different SWF, and the use of loader _flash as

Source: Internet
Author: User
Tags addchild
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.