Learn a little flash (29) addchild () every day to add objects to the container

Source: Internet
Author: User

Today, we found that addchild () is a few useful things. If you do not have attachmovie to copy a movie, you need to create a new movie scene. as3.0 unifies the creation of new XXX.

 

 

First, create a new video clip named Mc. Face this video clip in the library and select

 


 

Add the code in the first frame of the scene to display it:

VaR A: MC = new MC ();

Addchild ();

 

It is very simple to show that it is very different from the attachmovie () usage of as 2.0.

 

Suppose we want to copy Multiple balls:

 

 

For (var I: Int = 0; I <3; I ++)

{Var A: MC = new MC ();

 

Addchild (a); // Add to container

A. X = I * A. width; // different coordinates are displayed.

}

When we want to delete a video, we will perform a simple test:

BTN. addeventlistener (mouseevent. Click, del)

For (var I: Int = 0; I <3; I ++)
{
VaR A: MC = new MC ();
Addchild ();
A. Name = "A" + I;
}

For (var j: Int = 0; j <3; j ++)
{
VaR B: mymc = new mymc ();
Addchild (B );
B. Name = "B" + J;
B. x = J * B. width;
B. Y = J * B. width;
}
VaR T: Int = 0;
Function del (Event: mouseevent): void
{
If (T <3)
{Removechild (getchildbyname ("B" + T ));
T ++;
}
 
Else {

Trace ("deleted ");

}
 
}

Create a button to listen. When the mouse receives a message, it deletes one button every time until it is deleted.

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.