Summary of Flash ActionScript 3 Programming

Source: Internet
Author: User

Recently, I used as3 to write some projects. I encountered many problems during programming and gained some experiences. Now I hope it will be helpful for you to program in as3. If you find something wrong, you can point it out and discuss it together.

1. Forced type conversion of as3

I have always thought that this function is not available, but I recently read some documents and found that this function is available. At present, there are two methods to summarize:

    1. VaR Loader: urlloader = urlloader(event.tar get );

       

      I don't know if this method is a reference.Programming LanguageI have never seen it.

      Add this syntax description: http://livedocs.adobe.com/flash/8_cn/main/00001211.html

    2. VaR Loader: urlloader = event.tar get as urlloader;

       

      This method draws on the VB. NET programming language! As3 syntax is a hodgedge.

 

2. urlstream and urlloader

Urlstream supports multiple character encodings in text file data.

Urlloader after the test, found that in addition to the UTF-8 character encoding, other character encoding read data are garbled.

Bytearray object character encoding conversion (thanks to abc12hjc for providing additional informationCode):

Public class moxieas extends Sprite

{

Public Function moxieas ()

{

VaR stream: urlstream = new urlstream;

Stream. addeventlistener (event. Complete, complete );

Stream. Load (New URLRequest ("TTT. xml"); // <root> <A/> <B/> <C/> </root>

}

Private function complete (Event: Event): void

{

VaR stream: urlstream = event.tar get as urlstream;

VaR XML: xml = XML (stream. readutfbytes (stream. bytesavailable ));

Trace (XML. *. Length (); // output 3

}

}

The specific method depends on the actual functional requirements.

3. URLRequest

Urlstream, urlloader, loader, and other classes that read external data. The value of the load method parameter is the URLRequest object. In programming, I always like to write address strings directly. It seems to take some time.

4. Loader

When loading data using loader and adding listening events, be sure to add events to the contentloaderinfo attribute of Loader instead of adding events to the loader object. I am so depressed that I almost threw my computer away because of the error object (the key is that no error was reported during compilation.

Incorrect syntax:

VaR Loader: loader = new loader ();

Loader. addeventlistener (event. Complete, completehandler );

Loader. addeventlistener (securityerrorevent. security_error, securityerrorhandler );

Loader. addeventlistener (ioerrorevent. io_error, ioerrorhandler );

Correct syntax:

VaR Loader: loader = new loader ();

Loader. contentloaderinfo. addeventlistener (event. Complete, completehandler );

Loader. contentloaderinfo. addeventlistener (securityerrorevent. security_error, securityerrorhandler );

Loader. contentloaderinfo. addeventlistener (ioerrorevent. io_error, ioerrorhandler );

5. Data Types loaded by loader

We all know that loader is used to replace the loadmovie function of movieclip and load external image files and SWF files.

    • If an image file (JPG, GIF, PNG, etc.) is loaded, the Data Type obtained by loader. Content is a bitmap object;
    • If the SWF file (Flash 9) is loaded, the Data Type obtained by loader. Content is movieclip;
    • If the SWF file (earlier than Flash 9) is loaded, the Data Type obtained by loader. Content is avm1movie;

 

6. Stage

During flash debugging, if the SWF file is placed on the HTML page, the values of stage. stagewidth and stage. stageheight are null during the first loading call;

7. avm1movie

If it is an avm1movie object, you cannot directly call the stop, play, gotoandstop and other functions of the original movieclip object, and cannot convert the avm1movie object to a movieclip object. Current solution: use Flash CS3 to regenerate the SWF file of Flash 9; the other is the way for foreign websites to say that avm1 and avm2 virtual machines can call each other (paste an address );

8. Mask

When the mask function is used, a problem is found. If the display element used for the mask is not added to the display container of the same level through the addchild method, the mask effect is not displayed normally, I don't know if this is a bug. I almost gave up as3 and switched to as2.

Conversion from http://blog.163.com/lihua61622137@126/blog/static/553499122007112832153684)

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.