<< Chapter < Page Chapter >> Page >

Resources

I will publish a list containing links to ActionScript resources as a separate document. Search for ActionScript Resources in theConnexions search box.

Complete program listings

Complete listings of the ActionScript and MXML files discussed in this lesson are provided in Listing 10 through Listing 16 below.

Listing for the file named interface01.mxml.

<?xml version="1.0" encoding="utf-8"?><!--Illustrates polymorphism using an interface.--><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"xmlns:cc="CustomClasses.*"><cc:Driver/></mx:Application>
Listing

Listing for the file named driver.as.

package CustomClasses{ import flash.events.*;import mx.containers.HBox;import mx.containers.VBox; import mx.controls.Button;import mx.controls.Label; import mx.controls.TextArea;public class Driver extends VBox{private var textArea:TextArea = new TextArea(); private var myShape:IArea;private var randomChoice:Number;private var radius:uint; private var rectWidth:uint;private var rectHeight:uint;public function Driver(){//constructor var label:Label = new Label();label.text = "Interface Polymorphism Demo"; label.setStyle("fontSize",14);label.setStyle("color",0xFFFF00); addChild(label);//Put three buttons in an HBoxvar hbox:HBox = new HBox(); addChild(hbox);var areaButton:Button = new Button();areaButton.label = "Area"; hbox.addChild(areaButton);var circButton:Button = new Button();circButton.label = "Circumference"; hbox.addChild(circButton);var volumeButton:Button = new Button();volumeButton.label = "Volume"; hbox.addChild(volumeButton);//Put the text area below the HBox.textArea.width = 245; textArea.height = 80;addChild(textArea);//Register a click event handler on each of the // buttonsareaButton.addEventListener( MouseEvent.CLICK,areaButtonHandler);circButton.addEventListener(MouseEvent.CLICK,circButtonHandler);volumeButton.addEventListener( MouseEvent.CLICK,volumeButtonHandler);}//end constructor//Local utility method for getting and saving four // random values.private function getRandomValues():void{ randomChoice = Math.random();radius = uint(10*Math.random() + 1); rectWidth = uint(10*Math.random() + 1);rectHeight = uint(10*Math.random() + 1); }//end getRandomValues//Define click event handler methods.private function areaButtonHandler( 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.area();}//end areaButtonHandler 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

Listing for the file named iarea.as.

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

Listing for the file named ivolume.as.

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

Listing for the file named icircumference.as.

package CustomClasses{ public interface ICircumference{function circumference():String; }//end interface}//end package

Listing for the file named mycircle.as.

package CustomClasses{ public class MyCircle implements IArea{private var radius:Number;public function MyCircle(radius:Number){//constructor this.radius = radius;}//end constructorpublic function area():String{ return "Radius = " + radius + "\n" +"Area = " + Math.PI * radius * radius; }//end areapublic function id():String{return "Circle\n"; }//end idpublic function circumference():String{return "Radius = " + radius + "\n" + "Circumference = " + 2 * Math.PI * radius;}//end function circumferencepublic function volume():String{ //Assumes that the shape is a cylinder with a// depth of ten units. return "Radius = " + radius + "\n" +"Depth = 10\n" + "Volume = " + 10 * Math.PI * radius * radius;}//end area}//end class }//end package

Listing for the file named myrectangle.as.

package CustomClasses{ public class MyRectangle implements IArea{private var width:Number; private var height:Number;public function MyRectangle(width:Number,height:Number){//constructor this.width = width;this.height = height; }//end constructorpublic function area():String{ return "Width = " + width + "\n" +"Height = " + height + "\n" + "Area = " + width * height;}//end areapublic function id():String{ return "Rectangle\n";}//end idpublic function circumference():String{ return "Width = " + width + "\n" +"Height = " + height + "\n" + "Circumference = " + 2 * (width + height);}//end function circumferencepublic function volume():String{ //Assumes that the shape is a rectangular solid// with a depth of ten units. return "Width = " + width + "\n" +"Height = " + height + "\n" + "Depth = 10\n" +"Volume = " + 10 * width * height; }//end area}//end class}//end package

Miscellaneous

This section contains a variety of miscellaneous materials.

Housekeeping material
  • Module name: Interface Polymorphism - The Big Picture
  • Files:
    • ActionScript0112\ActionScript0112.htm
    • ActionScript0112\Connexions\ActionScriptXhtml0112.htm
PDF disclaimer: Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

-end-

Questions & Answers

it is the relatively stable flow of income
Chidubem Reply
what is circular flow of income
Divine Reply
branches of macroeconomics
SHEDRACK Reply
what is Flexible exchang rate?
poudel Reply
is gdp a reliable measurement of wealth
Atega Reply
introduction to econometrics
Husseini Reply
Hi
mostafa
hi
LEMLEM
hello
Sammol
hi
Mahesh
bi
Ruqayat
hi
Ruqayat
Hi fellas
Nyawa
hey
Sammol
hi
God
hello
Jahara
Good morning
Jorge
hi
abubakar
hi
Nmesoma
hi
Mahesh
Hi
Tom
Why is unemployment rate never zero at full employment?
Priyanka Reply
bcoz of existence of frictional unemployment in our economy.
Umashankar
what is flexible exchang rate?
poudel
due to existence of the pple with disabilities
Abdulraufu
the demand of a good rises, causing the demand for another good to fall
Rushawn Reply
is it possible to leave every good at the same level
Joseph
I don't think so. because check it, if the demand for chicken increases, people will no longer consume fish like they used to causing a fall in the demand for fish
Anuolu
is not really possible to let the value of a goods to be same at the same time.....
Salome
Suppose the inflation rate is 6%, does it mean that all the goods you purchase will cost 6% more than previous year? Provide with reasoning.
Geetha Reply
Not necessarily. To measure the inflation rate economists normally use an averaged price index of a basket of certain goods. So if you purchase goods included in the basket, you will notice that you pay 6% more, otherwise not necessarily.
Waeth
discus major problems of macroeconomics
Alii Reply
what is the problem of macroeconomics
Yoal
Economic growth Stable prices and low unemployment
Ephraim
explain inflationcause and itis degre
Miresa Reply
what is inflation
Getu
increase in general price levels
WEETO
Good day How do I calculate this question: C= 100+5yd G= 2000 T= 2000 I(planned)=200. Suppose the actual output is 3000. What is the level of planned expenditures at this level of output?
Chisomo Reply
how to calculate actual output?
Chisomo
how to calculate the equilibrium income
Beshir
Criteria for determining money supply
Thapase Reply
who we can define macroeconomics in one line
Muhammad
Aggregate demand
Mohammed
C=k100 +9y and i=k50.calculate the equilibrium level of output
Mercy Reply
Hi
Isiaka
Hi
Geli
hy
Man
👋
Bahunda
hy how are you?
Man
ys
Amisha
how are you guys
Sekou
f9 guys
Amisha
how are you guys
Sekou
ys am also fine
Amisha
fine and you guys
Geli
from Nepal
Amisha
nawalparasi district from belatari
Amisha
nd u
Amisha
I am Camara from Guinea west Africa... happy to meet you guys here
Sekou
ma management ho
Amisha
ahile becheclor ho
Amisha
hjr ktm bta ho ani k kaam grnu hunxa tw
Amisha
belatari
Amisha
1st year ho
Amisha
nd u
Amisha
ahh
Amisha
kaha biratnagar
Amisha
ys
Amisha
kina k vo
Amisha
money as unit of account means what?
Kalombe
A unit of account is something that can be used to value goods and services and make calculations
Jim
all of you please speak in English I can't understand you're language
Muhammad
I want to know how can we define macroeconomics in one line
Muhammad
it must be .9 or 0.9 no Mpc is greater than 1 Y=100+.9Y+50 Y-.9Y=150 0.1Y/0.1=150/0.1 Y=1500
Kalombe
Mercy is it clear?😋
Kalombe
hi can someone help me on this question If a negative shocks shifts the IS curve to the left, what type of policy do you suggest so as to stabilize the level of output? discuss your answer using appropriate graph.
Galge Reply
if interest rate is increased this will will reduce the level of income shifting the curve to the left ◀️
Kalombe
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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