13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with bitmaps<br />

import flash.display.Bitmap;<br />

import flash.display.BitmapData;<br />

var myPar<strong>en</strong>tSquareBitmap:BitmapData = new BitmapData(100, 100, false, 0x00ff3300);<br />

var myClonedChild:BitmapData = myPar<strong>en</strong>tSquareBitmap.clone();<br />

var myPar<strong>en</strong>tSquareContainer:Bitmap = new Bitmap(myPar<strong>en</strong>tSquareBitmap);<br />

this.addChild(myPar<strong>en</strong>tSquareContainer);<br />

var myClonedChildContainer:Bitmap = new Bitmap(myClonedChild);<br />

this.addChild(myClonedChildContainer);<br />

myClonedChildContainer.x = 110;<br />

The copyPixels() method is a quick and easy way of copying pixels from one BitmapData object to another. The<br />

method takes a rectangular snapshot (defined by the sourceRect parameter) of the source image and copies it to<br />

another rectangular area (of equal size). The location of the newly “pasted” rectangle is defined within the destPoint<br />

parameter.<br />

The copyChannel() method samples a predefined color channel value (alpha, red, gre<strong>en</strong>, or blue) from a source<br />

BitmapData object and copies it into a channel of a destination BitmapData object. Calling this method does not affect<br />

the other channels in the destination BitmapData object.<br />

The draw() and drawWithQuality() methods draw, or r<strong>en</strong>der, the graphical cont<strong>en</strong>t from a source sprite, movie clip,<br />

or other display object on to a new bitmap. Using the matrix, colorTransform, bl<strong>en</strong>dMode, and destination<br />

clipRect parameters, you can modify the way in which the new bitmap is r<strong>en</strong>dered. This method uses the vector<br />

r<strong>en</strong>derer in Flash Player and AIR to g<strong>en</strong>erate the data.<br />

Wh<strong>en</strong> you call draw() or drawWithQuality(), you pass the source object (sprite, movie clip, or other display object)<br />

as the first parameter, as demonstrated here:<br />

myBitmap.draw(movieClip);<br />

If the source object has had any transformations (color, matrix, and so forth) applied to it after it was originally loaded,<br />

these transformations are not copied across to the new object. If you want to copy the transformations to the new<br />

bitmap, th<strong>en</strong> you need to copy the value of the transform property from the original object to the transform property<br />

of the Bitmap object that uses the new BitmapData object.<br />

Compressing bitmap data<br />

Flash Player 11.3 and later, AIR 3.3 and later<br />

The flash.display.BitmapData.<strong>en</strong>code() method lets you natively compress bitmap data into one of the<br />

following image compression formats:<br />

PNG - Uses PNG compression, optionally using fast compression, which emphasizes compression speed over file<br />

size. To use PNG compression, pass a new flash.display.PNGEncoderOptions object as the second parameter<br />

of the BitmapData.<strong>en</strong>code() method.<br />

JPEG - Uses JPEG compression, optionally specifying image quality. To use JPEG compression, pass a new<br />

flash.display.JPEGEncoderOptions object as the second parameter of the BitmapData.<strong>en</strong>code() method.<br />

JPEGXR - Uses JPEG Ext<strong>en</strong>ded Range (XR) compression, optionally specifying color channel, lossy, and <strong>en</strong>tropy<br />

settings. To use JPEGXR compression, pass a new flash.display.JPEGXREncoderOptions object as the second<br />

parameter of the BitmapData.<strong>en</strong>code() method.<br />

Last updated 6/6/2012<br />

249

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!