<< Chapter < Page | Chapter >> Page > |
var bitmapObj:Bitmap = new Bitmap(bitmapData);
addChild(bitmapObj);} //end constructor
} //end class} //end package
Add the new Bitmap object to the display
Then Listing 3 calls the addChild method on the Sprite object to add the new Bitmap object to the display. This produces the screen output shown in Figure 1.
Simple enough?
This seems simple enough - right? However, there is a potential problem. In particular, an ActionScript project does not have access to any of those greatFlex components. Therefore, if you are going to create ActionScript projects, you will need to have access to similar resources from some other source.
Not compatible with Flex
This is the form of the sample programs provided in the ActionScript documentation on the two web pages listed above . Unfortunately, I didn't see a warning on either of those pages to the effectthat the programs are not compatible with Flex. I finally found a comment at the bottom of a different documentation page that gave me the first clue about thecompatibility problem.
In this program, I will show you how to update the program named Bitmap03 to make it compatible with Flex.
MXML code for the program named Bitmap04
We will begin with the MXML code shown in Listing 4 and repeated in Listing 9 for your convenience.
<?xml version="1.0" encoding="utf-8"?><mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cc="CustomClasses.*"><cc:Driver/></mx:Application>
Two files
This program consists of two files. One file, named Bitmap04.mxml contains the code shown in Listing 4. The other file named Driver.as contains the definition of a class named Driver . It is located in a package folder named CustomClasses , leading to the namespace declaration in Listing 4.
Instantiate an object of the Driver class
As you can see, the MXML code in Listing 4 simply instantiates an object of the Driver class. Beyond that point, the behavior of the program is completely controlled by ActionScript code.
Beginning of the Driver class for the program named Bitmap04
The Driver class begins in Listing 5. The code in Listing 5 is very similar to the code in Listing 1 with a few exceptions.
package CustomClasses{
import mx.containers.VBox;import flash.display.Bitmap;
import flash.display.BitmapData;import mx.core.UIComponent;public class Driver extends VBox{
//Note that this class extends Sprite, nothing shows// on the display. Therefore it extends VBox instead.
public function Driver(){//Prepare the display area. This is window dressing.
setStyle("backgroundAlpha",1.0);setStyle("backgroundColor",0x00FFFF);
width = 150;height = 150;//Create a BitmapData object with a red opaque
// background.var bitmapData:BitmapData =
new BitmapData(100, 100, false, 0xFF0000);
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?