Movieclip replication in as3

Source: Internet
Author: User

I believe that many people, like me, will be very curious to see that the familiar duplicatemovieclip and attachmovieclip have been removed (removed) in as3, how can I implement the "simple" function of copying MC in as3?

The clue given in the help is that the movieclip constructor is used to implement this function. This sentence seems like a mystery. How can a constructor have such a function?

So I tried to create a component in the scenario and open the link property of the component as before in the library. The ID in as3 is unavailable, so I should write a class name, after clicking "OK", the system prompts that the relevant as class file cannot be found and a file is automatically set. After this step, the components in this library become a class, then, return to the scenario and use the new operator name to create several components. The "copy" function is achieved in this way.

Using the for loop, you can also generate instances of new components in batches, which is also the result of batch replication.

VaR AR: array = new array (5 );
For (VAR I = 0; I <5; I ++ ){
Ar [I] = new MMC ();
Ar [I]. x = I * 10;
Ar [I]. Y = I * 10;
Addchild (AR [I]);
}

For those who are not familiar with as, we often face the implementation of some simple functions when we come into contact with as3. once these seemingly simple problems are solved one by one, so it is easier to get started with as3. Most of the people discussing as3 on the Internet are experts, and many people start with as3 from Flex. Therefore, many examples and codes start with package, the pure as file ending with curly braces is confusing. Does as3 have to start learning from a package?

I personally think this is not the case. Especially after flash 9 was launched, flash can still be used in some Flash files with timeline and code hybrid structure according to previous habits, it only changes the hierarchy of some classes. As a beginner, you can still write code in the timeline according to previous habits. User-defined classes are not used in As2, and can be rarely used in as3, this may be a civilian usage, but it is more conducive to our transition from as2 to as3.

Of course, the basic knowledge of the class is still necessary, especially in as3. many attributes of movieclip have been "dispersed" into its parent class. In this case, to understand whether a property exists or to understand the purpose of a property, you must search for it one by one from its parent class.

Send an example. The library contains a box line element, and add the shadow filter, and then convert it to a component. In the link Property Window of this component, set the class name to mymc2. The following code is used in the scenario, copy 5 MC and arrange them separately.

VaR AR: array = new array (5 );
For (VAR I = 0; I <5; I ++ ){
Ar [I] = new mymc2 ();
Ar [I]. x = I * 40 + 30;
Ar [I]. Y = (I % 2) * 20 + 30;
Addchild (AR [I]);
}

 

Download compressed package

TAG set: tags: as3 movieclip Replication

 

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.