<< Chapter < Page Chapter >> Page >

I am telling you this in the hope that this information will save you countless hours of searching through the documentation to discover why you get aruntime error when you replicate this project and then try to download and run it in the Flash Player plugin.

Beginning of the ActionScript Driver class

The MXML code shown in Listing 1 instantiates an object of the Driver class. The ActionScript Driver class begins in Listing 2.

Beginning of the actionscript driver class.

package CustomClasses{ import flash.display.Bitmap;import flash.display.BitmapData; import flash.display.Loader;import flash.events.*; import flash.geom.Rectangle;import flash.net.URLRequest; import flash.utils.ByteArray;import mx.containers.VBox;import mx.controls.Image; import flash.system.Security;//====================================================//public class Driver extends VBox { private var url:String = "snowscene.jpg";//image filepublic function Driver(){//constructor//Make the VBox visible. setStyle("backgroundColor",0xFFFF00);setStyle("backgroundAlpha",1.0);

Establish the name and path of the image file

The class definition in Listing 2 begins by declaring and populating an instance variable named url with the name of the image file shown in Figure 2. As you can see in Figure 2, this file was located in the samefolder as the MXML file. Therefore, no path information was required to specify the location of the image file.

The constructor

The constructor for the class also begins in Listing 2. This class extends the VBox class. The code in Listing 2 causes the background color of the VBox object to be yellow and also causes the yellow background to be completely opaque. You can see the opaque yellowbackground of the VBox object in Figure 1.

Opacity is often represented as either 1.0 or 255

Remember that I told you earlier that the opacity value is "often represented as either 1.0 or 255." Usually when you set the alpha value as a property of a Flex component, you must specify a value ranging from0.0 to 1.0 with a value of 1.0 being completely opaque. On the other hand, when you are dealing with the actual alpha value in bitmap data, you must specify avalue ranging from 0 to 255 with a value of 255 being completely opaque.

Start the process of loading the image file

Listing 3 starts the process of loading the image file. As I mentioned earlier, this program does not embed the image file in the SWF file. (The program named Bitmap06 , which I will explain later, does embed the image file in the SWF file.) Instead, the image file for this program ends up as a separate file on the server that must be downloaded in addition to the SWF file. (The ActionScript literature contains numerous discussions regarding the pros and cons ofembedding versus not embedding resource files.)

Start the process of loading the image file.

var loader:Loader = new Loader(); //Register event listeners on the load processloader.contentLoaderInfo.addEventListener( Event.COMPLETE,completeHandler);loader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR,ioErrorHandler);var request:URLRequest = new URLRequest(url);loader.load(request);

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask