<< Chapter < Page Chapter >> Page >

Nothing new here

There is nothing new in Listing 1, which consists almost entirely of importdirectives and instance variable declarations, so no further explanation of Listing 1 should be required. I will simply call your attention to the commentsregarding the FlashDevelop IDE at the beginning of Listing 1.

Beginning of the constructor for the Driver class

The constructor for the Driver class begins in Listing 2.

Beginning of the constructor for the driver class.

public function Driver(){//constructor //Make this Canvas visible.bkgndColor = (redBkgnd<<16) + (greenBkgnd<<8) + blueBkgnd;setStyle("backgroundColor", bkgndColor); setStyle("backgroundAlpha",0.5);

A 24-bit color value

The first statement in Listing 2 uses the left bitshift operator to construct a 24-bit binary value that will be used to establish the red,green, and blue values for the initial background color of the Canvas object. Hopefully you are already familiar with binary bit shifting. If not, just Google bitshift operator and you will find a lot of information on the topic. Note that the left bitshiftoperator is essentially the same in ActionScript, Java, C++, and other programming languages as well.

Set the initial background color and the transparency

Then Listing 2 calls the setStyle method twice in succession to set the background color and the transparency of that colorfor the background of the canvas.

An examination of the initial values for redBkgnd , greenBkgnd , and blueBkgnd in Listing 1 indicates that the initial background color is a dark shade of cyan with equal contributions ofgreen and blue and no red.

The transparency of the background color

The second call to the setStyle method in Listing 2 causes the background color to exhibit a 50-percent transparency or opacity.

It is important that the background color not be completely opaque. If it were opaque, it would not be possible to see the yellow moon and the yellowlightening bolts that are drawn on the canvas behind the background color.

Will change over time

The background color will be changed later in an event handler that is registered on a Timer object. The color will not only be subject to small random changes. It will also be subject to major changesswitching between the periods when a lightening flash is occurring or not occurring.

The remainder of the constructor

The remainder of the constructor is shown in Listing 3. There is nothing new in Listing 3 so no explanation beyond the embedded comments should be needed.

The remainder of the constructor.

//Load the two sky images and embed them in the // swf file.//Note the use of a / to eliminate the "Unable to // resolve asset for transcoding" Compiler Error[Embed("/normalsky.jpg")] var imgNormal:Class;normalSky.load(imgNormal);[Embed("/flippedsky.jpg")] var imgFlipped:Class;flippedSky.load(imgFlipped);//Load the treeImage and embed it in the swf file. [Embed("/tree.png")]var imgTree:Class; tree.load(imgTree);//Load sound files and play two of them. sizzle = new Sound();sizzle.load(new URLRequest("sizzle.mp3"));thunder = new Sound(); thunder.load(new URLRequest("thunder.mp3"));wind = new Sound();wind.load(new URLRequest("wind.mp3")); wind.play(0,2);//play twicerain = new Sound();rain.load(new URLRequest("rain.mp3")); rain.play(0, int.MAX_VALUE);//play forever//Register an event listener on the CREATION_ // COMPLETE event.this.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);//Save a reference to this Canvas object, which will // be used later for a variety of purposes.canvasObj = this;//Draw a yellow filled circle on this Canvas object.graphics.beginFill(0xffff00); graphics.drawCircle(circleX,circleY,radius);graphics.endFill();} //end constructor

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