Flash/flex Study Notes (33): How to Use as3 to coordinate Flash CS ide To control movieclip instances

Source: Internet
Author: User

After several years of development, as3 has completely evolved into an object-oriented (dynamic) language. However, many books about as3 often only pay attention to the as3 language itself, but it diluted how to work with Flash IDE.

1. On the flash timelineCodeCreate a movieclip instance defined in the external as file?

Assume that there is a myclip. As file externally with the following content:

 
Package {import flash. display. movieclip; public class myclip extends movieclip {public function myclip (): void {trace ("myclip constructor is called ");}}}

Create a new FLA file (Note: it must be in the same directory as myclip. As) and use it in the timeline Code as follows:

 
VaR clip1: myclip = new myclip ();

CTRL + press enter to test the video. In the output window, you will see: myclip constructor is called.

But some people may be depressed: In this case, all things should be controlled by pure as code. What should Flash CS do? It is better to write data directly in notepad and compile and finish the work, which does not reflect the strength of the Real-Time flash ide design. -- Look down

2. How to Use code to retrieve a movieclip instance designed with flash from the library?

It is the interface for creating a symbol in Flash cs4. Pay attention to the highlighted part. We can specify the class name and parent class at the time of creation so that the symbol can be referenced by code, we can use the powerful design functions of flash to first layout and place some controls, such as dynamic text, and then use them in the Code (note: in the following code, txtmsg is a dynamic text placed on myclip2)

 
VaR clip: myclip2 = new myclip2();clip.txt MSG. Text = "Hello world! "; Clip. x = 0; clip. Y = 0; clip. width = stage. stagewidth; addchild (CLIP );

3. combine the two cases above

That is, if we first create a movieclip-type symbol in Flash cs4 (and specify the class name myclip3 by referring to the method in 2), and then create a myclip3.as file in the same-level directory, can the two be used together?

The content of myclip3.as is as follows:

Package {import flash. display. movieclip; public class myclip3 extends movieclip {public function myclip3 (): void {trace ("myclip3's constuctor is called. "); txtmsg. TEXT = "myclip3's constuctor is called. "; // reference the dynamic file txtmsg placed on the myclip3 component during Flash CS design. // set txtmsg. text is encapsulated into the msgpublic function set MSG (V: string): void {trace ("MSG setter is called"); txtmsg. TEXT = V;} public function get MSG (): String {trace ("MSG getter is called"); Return txtmsg. text ;}}}

The timeline code in the home scene can be used as follows:

 
VaR clip: myclip3 = new myclip3();clip.txt MSG. Text = "Hello world! "; Trace (clip. MSG); clip. MSG = "hi"; clip. X = 0; clip. y = 0; clip. width = stage. stagewidth; addchild (CLIP );

The output window after running is as follows:

Myclip3's constuctor is called.
MSG getter is called
Hello world!
MSG setter is called

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.