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 />

Oft<strong>en</strong>, wh<strong>en</strong> bitmap images are scaled, they become blurred and distorted. To help reduce this distortion, use the<br />

smoothing property of the BitmapData class. This Boolean property, wh<strong>en</strong> set to true, smooths, or anti-aliases, the<br />

pixels within the image wh<strong>en</strong> it is scaled. This gives the image a clearer and more natural appearance.<br />

Understanding the BitmapData class<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The BitmapData class, which is in the flash.display package, can be lik<strong>en</strong>ed to a photographic snapshot of the pixels<br />

contained within a loaded or dynamically created bitmap image. This snapshot is repres<strong>en</strong>ted by an array of pixel data<br />

within the object. The BitmapData class also contains a series of built-in methods that are useful for creation and<br />

manipulation of pixel data.<br />

To instantiate a BitmapData object, use the following code:<br />

var myBitmap:BitmapData = new BitmapData(width:Number, height:Number, transpar<strong>en</strong>t:Boolean,<br />

fillColor:uinit);<br />

The width and height parameters specify the size of the bitmap. Starting with AIR 3 and Flash player 11, the size<br />

limits for a BitmapData object have be<strong>en</strong> removed. The maximum size of a bitmap is dep<strong>en</strong>d<strong>en</strong>t on the operating<br />

system.<br />

In AIR 1.5 and Flash Player 10, the maximum size for a BitmapData object is 8,191 pixels in width or height, and the<br />

total number of pixels cannot exceed 16,777,215 pixels. (So, if a BitmapData object is 8,191 pixels wide, it can only be<br />

2,048 pixels high.) In Flash Player 9 and earlier and AIR 1.1 and earlier, the limitation is 2,880 pixels in height and 2,880<br />

in width.<br />

The transpar<strong>en</strong>t parameter specifies whether the bitmap data includes an alpha channel (true) or not (false). The<br />

fillColor parameter is a 32-bit color value that specifies the background color, as well as the transpar<strong>en</strong>cy value (if<br />

it has be<strong>en</strong> set to true). The following example creates a BitmapData object with an orange background that is 50<br />

perc<strong>en</strong>t transpar<strong>en</strong>t:<br />

var myBitmap:BitmapData = new BitmapData(150, 150, true, 0x80FF3300);<br />

To r<strong>en</strong>der a newly created BitmapData object to the scre<strong>en</strong>, assign it to or wrap it in a Bitmap instance. To do this, you<br />

can either pass the BitmapData object as a parameter of the Bitmap object’s constructor, or you can assign it to the<br />

bitmapData property of an existing Bitmap instance. You must also add the Bitmap instance to the display list by<br />

calling the addChild() or addChildAt() methods of the display object container that will contain the Bitmap<br />

instance. For more information on working with the display list, see “Adding display objects to the display list” on<br />

page 158.<br />

The following example creates a BitmapData object with a red fill, and displays it in a Bitmap instance:<br />

var myBitmapDataObject:BitmapData = new BitmapData(150, 150, false, 0xFF0000);<br />

var myImage:Bitmap = new Bitmap(myBitmapDataObject);<br />

addChild(myImage);<br />

Manipulating pixels<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The BitmapData class contains a set of methods that allow you to manipulate pixel data values.<br />

Last updated 6/6/2012<br />

245

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

Saved successfully!

Ooh no, something went wrong!