Game Development Reference
In-Depth Information
Figure 4-13.
Exporting CrosshairsGif
The use of the image changes slightly in code when developing outside of the Flash IDE. This is
because the Flash IDE embeds all images in the library with the base class of
BitmapData
, while
Flex embeds them with the base class of
BitmapAsset
(a child of the
BitmapClass
). For this
reason, if you first write your code to work in the IDE, you will need to translate the usage from
BitmapData
to
Bitmap
. Here is an example for the
crosshairs.gif
image:
The Flash version:
private var crosshairs:Bitmap;
...
crosshairs = new Bitmap(new CrosshairsGif(0,0));
The Flex SDK version:
private var crosshairs:Bitmap;
crosshairs = new CrosshairsGif();
In the Flash version, we want the crosshairs to be a
Bitmap
instance so we can display it on the
screen. Because images are embedded in the IDE library with
BitMapData
as a base class, we
need to create the crosshairs
Bitmap
instance and pass it a call to create a new version of the
CrosshairsGif
library item.
In the Flex version, since
CrosshairsGif
is already embedded by default as a
BitmapAsset
(a
child of
Bitmap
), we simply need to create an instance of it and we are done.
Another example of differences in Flash/Flex embedding is in the
Ship
class. In the case of
Ship
,
we want the
imageBitmapData
variable to hold an instance of
BitmapData
not
Bitmap
. Here is the
embed code in Flex:
[Embed(source = "assets/flakassets.swf", symbol="ShipGif")]
private var ShipGif:Class;
Notice again that the
Class
created uses the same linkage name as in the IDE library version.
In the Flash IDE version, to create a new
BitmapData
instance, we simply call
new
on our linkage
name and pass in the width and height of the
BitmapData
.
//**** Flash *****
imagebd = new ShipGif(0,0);