<< Chapter < Page Chapter >> Page >

The end of the program

Listing 17 also signals the end of the program named Bitmap05 .

The program named Bitmap06

Behaves just like Bitmap05

This program behaves just like the program named Bitmap05. Therefore, the screen output shown in Figure 1 applies to this program as well as to theprogram named Bitmap05 .

The difference between the two programs

This program differs from the program named Bitmap05 in terms of how and when the image file is loaded. With the program named Bitmap05 , the image file was maintained as a separate file and downloaded with the SWF file. Then it wasloaded at runtime. This resulted in the security issue discussed earlier.

This program embeds the image file into the SWF file at compile time. Since there is no image file to be loaded from the local file system at runtime, thesecurity issue does not apply to this program.

Code modifications

As you might imagine, it was necessary to make some modifications to the program code to accomplish this difference. I will explain those modificationsin the following paragraphs.

MXML code for the program named Bitmap06

The MXML code for this program is the same as shown in Listing 19 for the program named Bitmap05 .

ActionScript code for the program named Bitmap06

I will present and explain only the code that is different from the program named Bitmap05 . However, a complete listing of the code for this program is provided in Listing 21 near the end of the lesson.

Code that is different in the program named Bitmap06

Listing 18 shows the code that is different in the program named Bitmap06 . Since some of the code is the same, I have highlighted the code that isdifferent with comments.

Code that is different in the program named bitmap06.

package CustomClasses{ import flash.display.Bitmap;import flash.display.BitmapData; import flash.geom.Rectangle;import flash.utils.ByteArray; import mx.containers.VBox;import mx.controls.Image; import mx.events.FlexEvent//different//====================================================//public class Driver extends VBox { private var image:Image = new Image();//differentpublic function Driver(){//constructor//Make the VBox visible. setStyle("backgroundColor",0xFFFF00);setStyle("backgroundAlpha",1.0); [Embed("snowscene.jpg")]//different var img:Class;//differentimage.load(img);//different//Note that the type of completion event specified // here is different from the type of completion// event used in Bitmap05. //Differentthis.addEventListener(FlexEvent.CREATION_COMPLETE, completeHandler);} //end constructor //--------------------------------------------------////This handler method is executed when the VBox has // been fully created. Note that the type of the// incoming parameter is more specific than was the // case in Bitmap05. However, it isn't used in this// program. //Differentprivate function completeHandler( event:mx.events.FlexEvent):void{//Get and save a reference to a Bitmap object // containing the content of the image file. This// statement is different from Bitmap05. //Differentvar original:Bitmap = Bitmap(image.content); //Everything beyond this point is identical to// Bitmap05 except that the IO error handler was // removed. It isn't needed for an embedded image// file.

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