Author Archive

Constructor Methods


A constructor method (or, constructor, for short) is a discrete set of instructions used
to initialize the instances of a class. To create a constructor method, we use a function
definition within a class block, as shown in the following generalized code:
class SomeClass {
function SomeClass ( ) {
}
}
In the preceding code, the keyword function begins the constructor method. Next
comes the constructor method name, which must exactly match the class name (case
sensitivity matters!). The constructor method name is followed by a pair of parentheses
that contain a list of constructor parameters, which we’ll study later. The curly
braces ({}) following the parameter list are a block statement, just like the block
statements in package and class definitions. A constructor method’s block statement
is known as the constructor body. The constructor body contains the directives that
initialize instances. Whenever a new instance of SomeClass is created, the directives in
the constructor body are executed (sequentially, from top to bottom). Executing the
directives in the constructor body is known as executing the constructor or, more
casually, running the constructor.
Constructor methods are created using the function keyword because
they are, technically speaking, a type of function. We’ll study functions
in Chapter 5.


When a class does not define a constructor function explicitly, ActionScript automatically
provides a default constructor that performs no initialization on new
instances of the class. Despite this convenience, as a best practice, always include a
constructor, even if it is just an empty one. The empty constructor serves as a formal

 

indication that the class design does not require a constructor and should be accompanied
by a comment to that effect. For example:
class SomeClass {
// Empty constructor. This class does not require initialization.
function SomeClass ( ) {
}
}
Unlike classes, the accessibility of constructor methods cannot be controlled with
access-control modifiers. In ActionScript 3.0, all constructor methods are implicitly
considered public. (Future versions of ActionScript might, however, allow for nonpublic
constructor methods.) As a matter of style, this book always includes the
public access-control modifier when defining constructor methods, stressing the fact
that all constructor methods must be public. The following code demonstrates:
class SomeClass {
public function SomeClass ( ) {
}
}
The rule that constructor methods must be public in ActionScript 3.0
was instituted due to engineering time constraints and volatility of the
ECMAScript 4 Language Specification. For details, see Sho Kuwamoto’s
article at: http://kuwamoto.org/2006/04/05/as3-on-the-lack-ofprivate-
and-protected-constructors. (Sho is Adobe’s FlexBuilder 2’s
development team lead.)
The constructor method of an application’s main class plays a special role in a program.
It provides an opportunity to execute code immediately after the application
has started. As such, the constructor method of an application’s main class is considered
the program point of entry.
The following code adds a constructor method to our VirtualZoo class (shown in
bold):
package zoo {
public class VirtualZoo {
public function VirtualZoo ( ) {
}
}
}
Our application now has an official point of entry. When our application starts, the
Flash runtime will automatically create a VirtualZoo instance, executing the
VirtualZoo constructor method in the process. Given that our application is a virtual
zoo, the first thing we’ll do in the VirtualZoo constructor method is create a
VirtualPet object (i.e., add a pet to the zoo). We’ll learn how to create objects next.

Twitter Updates for 2009-11-25

wir werden die http://www.clic…

wir werden die http://www.clickandsell.info/ zum Portal umbauen und einige spannende Online Dienste für SEO und SEM bieten

Tolle Marktplatz

www.freelance-market.de – Der effiziente Marktplatz für freie Mitarbeiter aller Art. Unternehmen finden hier umsonst qualifizierte Freiberufler mit besonders günstigen Stundensätzen. Vom Ingenieur, Designer, Eventmanger bis zur Schreibkraft.
Auf Wunsch können Sie den Linktext auch anpassen oder kürzen

Twitter Updates for 2009-11-24

  • Freitag gehen wir zu Hypnose wegen rauchen stoppen … Preis, 110 €, abgehalten wrd's in Englisch. Ich halt euch auf den laufenden #

Freitag gehen wir zu Hypnose w…

Freitag gehen wir zu Hypnose wegen rauchen stoppen … Preis, 110 €, abgehalten wrd’s in Englisch. Ich halt euch auf den laufenden

interessantes Flash AS3 Project letztens gefunden

Das hier könnte für alle Flashinteressierten interessant sein:

 

http://flash-workshop.blogspot.com/search/label/ActionScript

 

http://flash-templatez.blogspot.com/

 

http://flash-workshop.blogspot.com/2009/02/flash-cs3-3d-rotating-menu.html

test chat

Mallorca-Index

Der Mallorca Suchkatalog

Keywords optimieren

Keywords Optimieren

Ab hier wird es etwas kompliziert, ob Sie das so ganz ohne Checklisten und eBook hinbekommen ist schwer zu sagen, wir drücken Ihnen aber die Daumen, nicht das dieser Kurs am Ende nicht nur kostenlos, sondern gar auch noch umsonst war. Funktionieren tut ea aber auf jeden Fall, wir selbst optimieren nur noch einmal im Monat und auch dann dauert es in der Regel keine 5 Minuten- Aber wie gesagt, wir haben es die ersten Monate auch erst einmal mit Checklisten gemacht, es ist halt nicht ganz einfach. 

 

Wir sind für Sie da!

Live Chat


  LiveZilla Live Help

   

Angebot anfordern

Clicken Sie auf das Bild und nehmen Sie sich eine Minute Zeit, um eine detaillierte Angebotsanfrage zu generieren.