flash predefined_symbols_bitmap

Displaying a bitmap image

In ActionScript 1 and 2, a BitmapData image could be displayed by being displayed in a MovieClip thanks to the MovieClip.attachBitmap method.

In ActionScript 3 if we try to add a BitmapData type graphic object to the display list we get the following compilation error:

1067: Implicit coercion of a value of type flash.display:BitmapData 
value to an unrelated type flash.display:DisplayObject.

To add a BitmapData to the display list we have to wrap it in a Bitmap type display. This allows us to position the BitmapData object at a later date and to carry out other manipulations on it.

We instantiate a Bitmap object, then we go inside its BitmapData object constructor to wrap it:

var myBitmapData:LogoWiiFlash = new LogoWiiFlash(0, 0);
var myBitmap:Bitmap = new Bitmap( myBitmapData );
addChild ( myBitmap );

Once the image is compiled it is displayed:

5.3.1.jpg

The flash.display.Bitmap class inherited from the flash.display.DisplayObject class possesses all of the properties and methods necessary for the manipulation of a graphic object.

To do a translation and a rotation of our image we write the following:

var myBitmapData:LogoWiiFlash = new LogoWiiFlash(0, 0);
var myBitmap:Bitmap = new Bitmap( myBitmapData );
addChild ( myBitmap );
myBitmap.smoothing = true;
myBitmap.rotation = 45;
myBitmap.x += 250;

The previous code produces the following result:

5.3.2.jpg

We go into more detail about the bitmap class in the article entitled Bitmap programming.

Worth remembering

  • A symbol type graphic cannot be manipulated from the library through programming.
  • If an image is associated with the flash.display.BitmapData type, to display this we need to wrap it in a flash.display.Bitmap object.







Adobe Training center


Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42