Practical as3 code Collection [reprint]

Source: Internet
Author: User
Tags addchild

(1) interactivepng class

Make transparent pixels in PNG images no longer respond to mouse interaction.

Usage: In the flash library, set the movieclip "link property" base class containing PNG images to the interactivepng class.

Download: interactivepng_00000.zip

(2) stats class

This allows you to easily view the current SWF status: FPS, memory usage. Very convenient.

As3 code
  1. Addchild (new stats ());
  2. Addchild (new stats ({BG: 0x202020, FPS: 0xc0c0c0, Ms: 0x505050, Mem: 0x707070, memmax: 0xa0a0a0 }));

(3) fontloader class

If you want to apply a non-system font to the dynamic text in SWF, the method is to embed the corresponding font in the SWF. Another method is to embed the font into another SWF, when the corresponding font is required, load the SWF and reference the corresponding font. Fontloader is a font loading class that helps you implement this process.

In fonts.swf:

As3 code
  1. VaR _ Loader: fontloader = new fontloader ();
  2. _ Loader. Load (New URLRequest ('fonts.swf '));

After loading, You can reference the font:

As3 code
  1. VaR fonts = _ loader. fonts; var TF: textformat = new textformat (fonts [0]. fontname, 20 );

Download: http://code.google.com/p/collisiondetectionkit/

(4) collision detection kit

A collision detection toolkit written by as3. Detection Based on pixels and shapes is supported.

Download: http://code.google.com/p/collisiondetectionkit/

 

(5) swfupload class library

Swfupload is a JS + flash class library, which enables flash upload and retrieval progress and achieves Ajax-like effects without page overloading.

Usage, introduce the JS file:

As3 code
  1. <SCRIPT src = "http://www.swfupload.org/swfupload.js" type = "text/JavaScript"> </SCRIPT>

Create a swfupload object and specify the SWF. The SwF calls up the upload dialog box through the filereference class. Then, it is handed over to Js.

As3 code
  1. VaR swfu = new swfupload ({upload_url: "http://www.swfupload.org/upload.php", flash_url: "http://www.swfupload.org/swfupload.swf", file_size_limit: "200 MB", upload_start_handler: uploadstarteventhandler, Handler: Handler });

Download: http://code.google.com/p/swfupload/downloads/list

 

(6) bitmap mosaic class

Create a pixel bitmap for the Display object.

As3 code
  1. VaR mymoz: Mosaic = new mosaic (yourdisplayobj );
  2. Mymoz. pixelsize = 10;
  3. Mymoz. Render ();

Download: mosaic.zip

 

(7) Object pool class

Flash Player has two overhead operations: Object creation and garbage collection ). If we store unnecessary objects in an object pool, we can directly obtain the objects of the same type from the object pool. In this way, the "Object creation" can be reduced, and the garbage collection mechanism does not work in the object pool, thus reducing the overhead.

Usage:

Get an instance of someclass from objectpool:

As3 code
  1. VaR OBJ: someclass = objectpool. GetObject (someclass );

If you do not need an object, store it in the object pool:

As3 code
  1. Objectpool. disposeobject (OBJ );

Download: objectpool.zip

 

 

(8) swfwheel class

Resolve the conflict between the middle mouse button and the browser. Declare the js method in the as code and call it through externalinterface. Other JS files are not required at all.

As3 code
  1. Swfwheel. initialize (this. stage );

Download: swfwheel.

 

(9) greenthread class

It dynamically allocates a number of computations (in the thread simulation mode) to multiple frames for computation to avoid the phenomenon of "frame cards. such as search algorithms, graphic Encoding algorithms, and massive data parsing. very useful.
You need to customize the subclass of greenthread extension and put the main cyclic computing in the run function.

As3 code
  1. VaR astar: astargreenthread = new astargreenthread ();
  2. Astar. addeventlistener (event. Complete, onfindpath );
  3. Astar. Star ();

Download: greenthreads-1.0.zip

Reprint address: http://uh.9ria.com/space.php? Uid = 3216 & Do = Blog & id = 3764

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.