<< Chapter < Page Chapter >> Page >

I will break this program down and explain it in fragments. Aside from the MXML file shown in Listing 14, the program consists of a single class named Driver . A complete listing of the Driver class file is provided in Listing 16 near the end of the lesson.

Beginning of the class named Driver

The Driver class begins in Listing 4. Note that this class extends the Panel class, causing this program to have the same overall appearance as the program provided in the documentation .

Beginning of driver class for effects03.

package CustomClasses{ import flash.events.MouseEvent;import mx.containers.ControlBar; import mx.containers.Panel;import mx.controls.Button; import mx.controls.Image;import mx.controls.TextArea; import mx.effects.Resize;import mx.events.EffectEvent; import mx.events.FlexEvent;public class Driver extends Panel{ //Instantiate and save references to all of the// objects required by the program. private var resize:Resize = new Resize();private var textOut:TextArea = new TextArea(); private var image:Image = new Image();private var bar:ControlBar = new ControlBar(); private var startButton:Button = new Button();private var pauseButton:Button = new Button(); private var resumeButton:Button = new Button();private var reverseButton:Button = new Button(); private var endButton:Button = new Button();private var resetButton:Button = new Button();

In addition to containing all of the required import directives, the code in Listing 4 instantiates and saves references to all of the objects required bythe program.

Beginning of the constructor for Effects03

The constructor begins in Listing 5.

Beginning of the constructor for effects03.

public function Driver(){//constructor this.title="Demonstration of the Resize effect.";this.percentWidth = 100; this.percentHeight = 100;this.addEventListener(FlexEvent.CREATION_COMPLETE,creationCompleteHandler);

The code in Listing 5 sets several properties on the Panel object, which is the object with the light gray background shown in Figure 4. The Panel object is displayed in the browser window, which has a slightly darker gray background color in Figure 4.

Register an event listener

The last statement in Listing 5 registers an event listener named creationCompleteHandler to service creationComplete events dispatched by the Panel object.

As you will see later, the event handler causes the text "Creation Complete!" to be displayed in a TextArea object near the top of the Panel in Figure 4 when the Panel object and all of its children have been constructed, initialized, and drawn.

Prepare the TextArea object and add it to the Panel

Listing 6 sets some properties and some styles on the TextArea object and adds it near the top of the Panel as shown in Figure 4.

Prepare the textarea object and add it to the panel.

textOut.percentWidth = 100;//percent textOut.height = 100;//pixelstextOut.setStyle("color","0x0000FF"); textOut.setStyle("fontSize",14);textOut.text = "Use the Buttons to control " + "the size of the image.";addChild(textOut);

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