<< Chapter < Page Chapter >> Page >

The end of the class

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

The file named MyShape.as

The class named MyShape is shown in its entirety in Listing 7, and also in Listing 11 near the end of the lesson.

The class named myshape.

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

The sole purpose

The sole purpose of the class named MyShape is to serve as the root of a hierarchy of more specialized shape classes and to provide a default versionof the area method that can be overridden in the subclasses.

The class accomplishes those things well, and beyond that, there isn't much to say about the code in Listing 7. Note that the class doesn't evendefine a constructor but instead uses the default constructor that is provided by the compiler.

The file named MyCircle.as

The class named MyCircle is shown in its entirety in Listing 8, and also in Listing 12 near the end of the lesson.

The class named mycircle.

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

The class named MyCircle is only slightly more complicated than the class named MyShape .

The constructor

The constructor for the class named MyCircle receives an incoming value for the radius and saves that value in a private instance variable named radius . Saving the value in an instance variable makes it available to the area method that will be executed later.

Type coercion

Recall from Listing 4 and Listing 5 that the value that is actually passed to the constructor is of type uint , which is an unsigned integer. That value is coerced to type Number by passing it as an argument that is defined to be of type Number .

An overridden area method

Note that the method named area is declared to be an override. This syntax is required by ActionScript when a method in a subclass overrides an inheritedmethod.

Return a String object

The code in the area method concatenates several individual strings (including the computed area of the circle) into a single String object and returns a reference to that object. A sample of the returned value is shown displayed in the text area of Figure 4.

Concatenation of strings with numeric values

The computed value of the area and the stored value of the radius are both numeric values. When a numeric value is concatenated with a string, thenumeric value is coerced into a string of characters, decimal points, etc., and the two strings are concatenated into a single string.

Computation of the area

As you can see in Listing 8, the area of the circle is computed as the square of the radius multiplied by the constant PI. (Hopefully you recall that formula from your high school geometry class.) As mentioned earlier, the resulting area value is concatenated with the string to its left where itbecomes part of the larger String object that is returned by the method.

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
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