Summary of as3 Programming

Source: Internet
Author: User

Summary of as3 Programming
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 based on that programming language. I have never seen it before.
(Supplement 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.
(Complement, which can be converted by bytearray object character encoding)

View plaincopy to clipboardprint?
  1. Public class moxieas extends Sprite
  2. {
  3. Public Function moxieas ()
  4. {
  5. VaR Loader: urlloader = new urlloader (New URLRequest ("TTT. xml"); // <root> <A> test </a> </root> encode by ANSI
  6. Loader. dataformat = urlloaderdataformat. Binary;
  7. Loader. addeventlistener (event. Complete, complete );
  8. }
  9. Private function complete (Event: Event): void
  10. {
  11. VaR BA: bytearray = new bytearray;
  12. Ba.writebytes(event.tar get as urlloader). Data );
  13. Ba. Position = 0;
  14. VaR XML: xml = XML (BA. readmultibyte (BA. length, "GBK "));
  15. Trace (XML. *); // output test
  16. }
  17. }

Public <br/> class moxieas extends sprite <br/>{< br/> Public Function <br/> moxieas () <br/>{< br/> var Loader: urlloader = new <br/> urlloader (New URLRequest ("TTT. XML "); // <br/> <root> <A> test </a> </root> encode by <br/> ANSI <br/> loader. dataformat = <br/> urlloaderdataformat. binary; <br/> loader. addeventlistener (event. complete, complete); <br/> <br/>}< br/> <br/> private function complete <br/> (Event: Event ): void <br/> {<br/> var BA: bytearray = new <br/> bytearray; <br/> ba.writebytes(event.tar get as <br/> urlloader ). data); <br/> BA. position = 0; <br/> var XML: xml = XML (BA. readmultibyte (BA. length, "GBK"); <br/> trace (XML. *); // output test <br/>}< br/>}
Thanks to abc12hjc for providing additional code

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.

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.