2007年5月23日星期三

Flash 9: BitmapData and Bitmaps from the Library

Flash 8 let you load bitmap information from the library using a linkage ID and the BitmapData.loadBitmap() method. This is no longer the case with Flash 9 and ActionScript 3. Now, as with timelines and movie clips in the library, Bitmaps are associated with classes. If you do not specify a specific class to be related to your bitmap in the library, you can name one which will be created automatically when publishing the SWF.

Classes associatated with bitmaps in the library are subclasses of BitmapData (flash.display.BitmapData). These are then instantiated as instances in ActionScript using the new keyword. As BitmapData instances, before being able to be seen on the screen, they would need to be associated with a Bitmap (flash.display.Bitmap) instance which is a display object capabale of being added to a display list (BitmapData instances cannot be added to display lists).

As an example, lets say you imported a bitmap of Rome in your library. In the linkage dialog for that bitmap, give it a class name of RomeImage - note that you don't have to create this class yourself; it will be created automatically. Then, to display it on the screen in ActionScript, use:

ActionScript Code:

// create instance of RomeImage bitmap data
var romeImageData:RomeImage = new RomeImage();

// create a bitmap instance that references the RomeImage instance
var romeImageBitmap:Bitmap = new Bitmap(romeImageData);

// add the new bitmap to the display list
addChild(romeImageBitmap);

0 评论: