<< Chapter < Page Chapter >> Page >

The other two click event handler methods.

private function circButtonHandler( event:MouseEvent):void{getRandomValues();if(randomChoice<0.5){ myShape = new MyCircle(radius);}else{ myShape = new MyRectangle(rectWidth,rectHeight);}//end else textArea.text = myShape.id() +myShape.circumference(); }//end circButtonHandlerprivate function volumeButtonHandler( event:MouseEvent):void{getRandomValues();if(randomChoice<0.5){ myShape = new MyCircle(radius);}else{ myShape = new MyRectangle(rectWidth,rectHeight);}//end else textArea.text = myShape.id() + myShape.volume();}//end circButtonHandler }//end class}//end package

The same methodology

The methodology behind these two event handlers is the same as the methodology behind the event handler method shown in Listing 5.

The main differences between the event handlers

The main differences appear in the two statements that begin with "textArea.text = " . In addition to using the reference of type IArea to call the id method on the objects, these two event handler methods call the circumference method or the volume method on the objects. Once again, this is possible only because the objects inherit those methods from the IArea interface.

The end of the Driver class

Listing 6 also signals the end of the class named Driver .

The file named IArea.as

Since I mentioned the interface named IArea several times above, I will discuss it next.

The interface named IArea is shown in Listing 7.

The interface named iarea.

package CustomClasses{ public interface IArea extends IVolume,ICircumference{function area():String; function id():String;}//end interface }//end package

General information about an interface

The syntax for an interface looks a lot like the syntax for a class. However, the keyword class is replaced by the keyword interface .

An interface may contain only method declarations (with no bodies) and setter and getter method declarations. All method declarations areimplicitly public , and the concrete definition of an interface method in a class must be declared public .

You cannot instantiate an object of an interface.

An interface cannot extend a class, but can extend any number of other interfaces.

IArea declares two methods and extends two interfaces

The interface shown in Listing 7 declares the abstract methods named area and id . It also extends the interfaces named IVolume and ICircumference .

Concrete method definitions are required

Any class that implements the interface named IArea must provide concrete definitions forthe methods named id and area .

The class must also provide concrete definitions for any methods inherited into IArea from the interfaces that it extends. The class also inherits those methods by way of IArea .

The file named IVolume.as

The interface named IVolume is shown in its entirety in Listing 8.

The interface named ivolume.

package CustomClasses{ public interface IVolume{function volume():String; }//end interface}//end package

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