Some summary about Flash AS3 programming

Source: Internet
Author: User
Tags html page
Programming

Recently wrote some projects with AS3, in the process of programming, encountered a lot of problems, but also some harvest and experience. Now it's going to be a bit of a help for everyone in AS3 programming. If you find something that is wrong, you can point it out and discuss it together.

1. Forced type conversion of AS3

I always thought there was no such feature, and recently I was looking at some documents and found that this feature is available. At present, there are two ways to write a conclusion:

    1. var loader:urlloader = Urlloader (event.target);
      I do not know this kind of writing is borrowed from that programming language, anyway I have not seen.
      Add this syntax Note:http://livedocs.adobe.com/flash/8_cn/main/00001211.html
    2. var loader:urlloader = event.target as Urlloader;
      This writing is borrowed from vb.net programming language, alas! AS3 Grammar is really a hodgepodge.

2, Urlstream and Urlloader

Urlstream can support multiple character encodings in the context of text file data.
Urlloader after the test, found that in addition to UTF-8 character encoding, other character encoding read the data are garbled.

can be converted by ByteArray object character encoding (thanks to ABC12HJC for supplemental code):

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.target as Urlstream;
var xml:xml = XML (Stream.readutfbytes (stream.bytesavailable));

Trace (Xml.*.length ()); Output 3
}
}

The specific way to see the actual functional requirements.

3, URLRequest

Urlstream, Urlloader, loader and other classes that read external data, the load method parameter value in is the URLRequest object. I always like to write the address string directly in the programming process, it seems that it will take some time to get used to it.

4, Loader

When you add a listening event when you use loader to load data, be aware that you must increase the event for the loader Contentloaderinfo property instead of adding events to the loader object. I just because of the wrong object (the key is compile-time has not given an error), so depressed almost to throw the computer.

Wrong wording:
var loader:loader = new Loader ();
Loader.addeventlistener (Event.complete, Completehandler);
Loader.addeventlistener (Securityerrorevent.security_error, Securityerrorhandler);
Loader.addeventlistener (Ioerrorevent.io_error, Ioerrorhandler);

Correct wording:
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, Loader loaded data type

Everyone knows loader is used to replace the original MovieClip Loadmovie function, used to load external picture files, SWF files.

    • If the picture file (Jpg,gif,png, etc.) is loaded, the Loader.content data type is bitmap object;
    • If the SWF file (Flash 9 version) is loaded, the Loader.content data type is the MovieClip object;
    • If the SWF file (previous version of Flash 9) is loaded, the Loader.content data type is Avm1movie object;

6, Stage

In debugging the flash process, if the SWF file is placed on the HTML page, stage.stagewidth and stage.stageheight are null when they first load the call;

7, Avm1movie

If you are Avm1movie objects, you cannot directly invoke the functionality of the original MovieClip objects such as stop,play,gotoandstop, and you cannot convert Avm1movie objects to MovieClip objects. The current solution: one is to regenerate Flash 9 swf files with flash CS3, and the other is that foreign websites have the means to AVM1 and AVM2 two virtual machines to call each other (put an address);

8, Mask

In the use of mask function, found a problem, if you do not use the mask for the display of the Addchild method to add to the same level of display container, the mask effect is not normal, do not know if this is a bug. I almost gave up AS3 for this problem 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.