<< Chapter < Page Chapter >> Page >

The file named MyRectangle.as

The class named MyRectangle is so similar to the class named MyCircle that it doesn't warrant a detailed explanation. A complete listing of the file is provided in Listing 13 near the end of the lesson.

The constructor receives and saves numeric values for the width and the height of the rectangle.

The overridden area method computes the area as the product of the width and the height and concatenates that information into a returned String object where it is displayed in the format shown in Figure 5.

Run the program

I encourage you to run this program from the web. Then copy the code from Listing 9 through Listing 13. Use thatcode to create a Flex project. Compile and run the project. Experiment with the code, making changes, and observing the results of yourchanges. Make certain that you can explain why your changes behave as theydo.

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 listing

Complete listings of the Flex and ActionScript files used in this program are provided in Listing 9 through Listing 13 below.

Listing of the file named polymorph02.mxml.

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

Listing of the file named driver.as.

package CustomClasses{ import flash.events.*;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();public function Driver(){//constructorvar label:Label = new Label(); label.text = "Polymorphism Demonstration";label.setStyle("fontSize",14); label.setStyle("color",0xFFFF00);addChild(label);var button:Button = new Button(); button.label = "GO";addChild(button);textArea.width = 200; textArea.height = 70;addChild(textArea);button.addEventListener( MouseEvent.CLICK,buttonHandler);}//end constructorprivate function buttonHandler( event:MouseEvent):void{var randomChoice:Number = Math.random(); var radius:uint = uint(10*Math.random() + 1);var width:uint = uint(10*Math.random() + 1); var height:uint = uint(10*Math.random() + 1);var myShape:MyShape;if(randomChoice<0.33333){ myShape = new MyShape();}else if(randomChoice<0.66666){ myShape = new MyCircle(radius);}else{ myShape = new MyRectangle(width,height);} textArea.text = myShape.area();}//end buttonHandler }//end class}//end package

Listing of the file named myshape.as.

package CustomClasses{ public class MyShape{public function area():String{ return "General Shape\n" +"Unable to compute area."; }// end area method}//end class }//end package

Listing of the file named mycircle.as.

package CustomClasses{ public class MyCircle extends MyShape{private var radius:Number;public function MyCircle(radius:Number){//constructor this.radius = radius;}//end constructoroverride public function area():String{ return "Circle\n" +"Radius = " + radius + "\n" + "Area = " + Math.PI * radius * radius;}//end area }//end class}//end package

Listing of the file named myrectangle.as

package CustomClasses{ public class MyRectangle extends MyShape{private var width:Number; private var height:Number;public function MyRectangle(width:Number,height:Number){//constructor this.width = width;this.height = height; }//end constructoroverride public function area():String{return "Rectangle\n" + "Width = " + width + "\n" +"Height = " + height + "\n" + "Area = " + width * height;}//end area }//end class}//end package

Miscellaneous

This section contains a variety of miscellaneous materials.

Housekeeping material
  • Module name: Polymorphism - The Big Picture
  • Files:
    • ActionScript0110\ActionScript0110.htm
    • ActionScript0110\Connexions\ActionScriptXhtml0110.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

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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