<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.23101-</id>
  <updated>2009-11-16T15:50:42Z</updated>
  <title>Comments for LFFS - 4: ActionScript 3.0 (http://www.insideria.com/2008/03/lffs-4-actionscript-30.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.23101</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=23101" title="LFFS - 4: ActionScript 3.0" />
    <published>2008-03-12T14:00:00Z</published>
    <updated>2008-11-24T22:13:25Z</updated>
    <title>LFFS - 4: ActionScript 3.0</title>
    <summary>As promised, the current installment of Learning Flex From Scratch focuses on the syntax of ActionScript 3.0. We know from the previous post that an application written in an object-oriented programming language involves, by definition, the use of objects. Objects, we found out, are derived from classes, which serve as a blueprint for the object&apos;s methods and properties. This post goes into the details of creating a class in ActionScript 3.0, providing a foundation for our journey into the language. The code examples provided here are strictly theoretical, and shouldn&apos;t be thought of as a working piece of software, but rather as a starting point to illustrate some basic language concepts.</summary>
    <author>
      <name><![CDATA[Adam Flater &amp; Scott Sheridan]]></name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[As promised, the current installment of <a href="http://www.insideria.com/adam-flater-scott-sheridan/" target="_blank"><strong>Learning Flex From Scratch</strong></a> focuses on the syntax of ActionScript 3.0. We know from the <a href="http://www.insideria.com/2008/02/lffs-3-object-oriented-languag.html" target="_blank">previous post</a> that an application written in an object-oriented programming language involves, by definition, the use of objects. Objects, we found out, are derived from classes, which serve as a blueprint for the object's methods and properties. This post goes into the details of creating a class in ActionScript 3.0, providing a foundation for our journey into the language. The code examples provided here are strictly theoretical, and shouldn't be thought of as a working piece of software, but rather as a starting point to illustrate some basic language concepts. <br/>
<br/>
ActionScript shares its lineage with a number of other languages, such as JavaScript, and JScript .NET. This is because these languages are all based on the ECMA-262 fourth edition language specification, and more specifically, ECMAScript. This language specification, developed by ECMA International, is currently under development as of March 2008, and is expected to be finalized in December 2008. By analyzing our theoretical class, we will be learning about many of ActionScript's keywords, rules of syntax, and guidelines for best practices. <br/>
<br/>
The code in the following example is an example of a theoretical construction of a class named Bicycle. Within the class definition are some of the various methods and properties you'd expect a bicycle to have. If you wanted to write an application in ActionScript that involved bicycles, you would of course have to define what bicycles are and what they do. But that wouldn't be enough. You'd also need to define classes for all of the parts of a bicycle that are referred to, (as well as any other objects you'd like to include that relate to these objects), and declare their properties and methods as well. A working program about bicycles would have several classes, all working in concert to provide a logical representation of whatever the programmer intended to demonstrate. We will be discussing the construction of a fully working program in future installments, but for now our focus is on learning the foundations of the language through the examination of a class. Let's begin.<br/>
<br/>
<strong>Comments</strong><br/>
<br/>
The first thing we run across in our code example is a series of comments. Comments are statements left by the programmer that won't get compiled as part of the application, but are used to help keep the code organized. It's considered good form to make use of comments so that your code can be followed more easily by others, and so that a potentially large amount of source code remains easy to navigate. According to the language specification, there are three types of comments used in ActionScript 3.0. For comments placed before a method, property, or class definition, the best practice is to use "/**" to start your comment and "*/" to finish it. For comments within a method, there are two accepted versions depending on the length of the comment. One line comments begin with "//". In fact, "//" literally means ignore everything after "//" until the next line. The "//" can occur at the beginning or the end of a line of source code. For comments within a method that spans multiple lines, you use this set of operators: <br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
"<span class="quote">/*</span>"[Comment]"<span class="quote"> */</span>".</pre>
</code>

</div></div> 
<strong>Package Declaration</strong><br/>
<br/>
A package declaration is the first part of an ActionScript class. It looks like: <font color="#800080">package</font> com.mycompany.myapplication, followed on the next line by an opening curly brace. This is a <em><strong>package declaration</strong></em>. A package is a conceptual container in which we can put our class declaration. You can legally declare a class (meaning it would be within the rules of ActionScript) without putting it in a package, but it's considered a best practice to use one. There are a few reasons why this is important. One reason for the use of packages is that a class name should ideally be unique within a program. One way to ensure this is by using a variation of a uniform resource locator (URL). In our example we use the reversed "com.mycompany.myapplication" URL as our unique name. Maintaining your classes within a uniquely named package allows you to more safely share code with other programmers. In the event that another programmer has created a class that has the same name as one in your application, you can still use that class without conflict if it's wrapped in a package. Classes take on their package name as part of their identity, and are thus guaranteed to be unique. <br/>
<br/>
Objects derived from classes within a package have access to only those objects within that package by default. In the event that you need to grant access to an object that's outside the package, you use the "import" keyword. You can choose to import the entire package, or just the class you need from the package. For example, if you would like to work with the flash MovieClip class within your package you would type: <br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">import</span> flash.display.<span class="category2">MovieClip</span>;</pre>
</code>

</div></div> 
<br/>
Following the package declaration, we have the opening curly brace that marks the beginning of the content of our package.<br/>
<br/>
<strong>Class Declaration</strong>
<br/>
The next piece of code that we run across is our class declaration. <br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">public</span> <span class="category1">class</span> Bicycle</pre>
</code>

</div></div> 
This is our declaration of the Bicycle class. By convention, class names are capitalized. If we had a banana seat bike class, then our class would be called BananaSeatBicycle . This kind of notation is called "camel case". The "class" keyword alerts the compiler to the fact that a class definition is on its way. By declaring the class "public" we are saying that code within this class may be accessed by code from another class. Next, we can see that, like our package declaration, our class definition has an opening curly brace. It is in between this opening brace and its subsequent closing brace that the class' body is located. The class body contains all of the methods, properties, and variables that belong to the class; in other words, its members. <br/>
<br/>
<strong>The Constructor Method</strong><br/>
<br/>
Next, we see another comment, this one announcing the presence of a constructor method. <br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="blockcomment">/**
* This is the constructor method, and it is always "public".
*/</span>
<span class="category1">public</span> <span class="category1">function</span> Bicycle( seatHeight : <span class="category1">int</span> = 0,
                                     typeOfBicycle : <span class="category2">String</span> = <span class="category1">null</span>,
                                     totalWeight : <span class="category1">int</span> = 0,
                                     currentGear : <span class="category1">int</span> = 0)</pre>
</code>

</div></div> 
<br/>
A constructor method, or simply <em><strong>constructor</strong></em>, is the set of instructions that are executed when an instance of a class is created (i.e. instantiated). As the comment lets us know, a constructor method is always public in ActionScript (but not in all OO languages). The compiler knows that it's a constructor method because the name of the method (Bicycle) is also the name of the class. Method declarations in ActionScript are written using the "function" keyword followed by the name of the function. Following the function name is a set of parentheses. It is within these parentheses that a method can hold additional information in the form of <em><strong>method parameters</strong></em>.<br/>
<br/>
In our example, the method parameters are: seatHeight, typeOfBicycle, totalWeight, and currentGear. Each of these parameters holds a certain type of data. In the case of seatHeight, we know the height of the seat is expressed by a whole number, and its default is 0. Our "typeOfBicycle" parameter is represented by data of <em><strong>String</strong></em> type. Possible candidates for a String value for this parameter might be: "road", "mountain", or "recumbent". <br/>
<br/>
A constructor's parameter is a special type of local variable. A local variable is a special type of variable (a representation of data in memory) that is used to represent data within a method. Local variables can only be accessed within the method in which they are defined, hence the term "local". In addition, local variables can only be used as long as the method in which they are defined is executing. When we refer to the area of an application in which a method, variable, or property "lives", we are speaking of that member's <em><strong>scope</strong></em>. Also, the time during which a variable is available is called it's <em><strong>lifetime</strong></em>. We'll talk more about <em><strong>scope</strong></em> and <em><strong>lifetime</strong></em> in subsequent posts. <br/>
<br/>
Our parameter names are followed by a ":" operator which is then followed by the data type and the variable's initial value. In ActionScript, and in other languages as well, the use of the ":" operator tells us that the term before it "is" one of whatever term follows it. For example, seatHeight : int = 0 means that the variable seatHeight is of the type int and initially equal to zero. <br/>
<br/>
In all, the first part of our constructor method tells us that for every instance of the Bicycle class, a space in memory is allocated for data represented by the local variables: seatHeight, typeOfBicycle, totalWeight, and currentGear. Because of the the way we have written our class, the values for each local variable could be supplied via the Constructor invocation or set directly on the properties of the object. Because local variables are only active as long as the method in which they have been defined is executing, we must do something more to ensure that the instance of our Bicycle object maintains a reference and/or copy of the data we'd like to save.<br/>
<br/>
The following code exists within the constructor method body: <br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
{
     <span class="category1">this</span>.seatHeight = seatHeight;
     <span class="category1">this</span>.typeOfBicycle = typeOfBicycle;
     <span class="category1">this</span>.totalWeight = totalWeight;
     <span class="category1">this</span>.currentGear = currentGear;
}</pre>
</code>

</div></div> 
<br/>
It tells us that this instance of the Bicycle class has allocated space in memory for data related to "<em><strong>seatHeight</strong></em>", "<em><strong>typeOfBicycle</strong></em>", "<em><strong>totalWeight</strong></em>", and "<em><strong>currentGear</strong></em>". The "this" keyword, followed by a ".", is used to signify the current object, in this case, the instantiated bicycle. It also tells us that these four variables are equal to the supplied initial values. <br/>
<br/>
<strong>Properties</strong><br/>
<br/>
The next stop on our "tour de code" is a declaration of the Bicycle class' properties: <br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="blockcomment">/**
* The following are the properties of a Bicycle in the Bicycle class.
*/</span>
<span class="category1">public</span> <span class="category1">var</span> seatHeight : <span class="category1">int</span> = 0;
<span class="category1">public</span> <span class="category1">var</span> typeOfBicycle : <span class="category2">String</span> = <span class="category1">null</span>;
<span class="category1">public</span> <span class="category1">var</span> totalWeight : <span class="category1">int</span> = 0;
<span class="category1">public</span> <span class="category1">var</span> currentGear : <span class="category1">int</span> = 0;</pre>
</code>

</div></div> 
<br/>
As you know, a class' properties are the descriptive data that are bundled within it. To declare a class property, we use the keyword "var" followed by the variable name and class name combination (like in the method parameter declaration), and followed then by the data type and value. We also declare the type of access the application may have on the property by using an access modifier. As is evident in the example, the properties of the Bicycle class are publicly accessible.<br/>
<br/>
<strong>Variables</strong><br/>
<br/>
Moving down farther, we come across a comment that alerts us to the fact that the Bicycle class' variables are declared next. <br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="blockcomment">/**
* The variables of Bicycle.
*/</span>
<span class="category1">private</span> <span class="category1">var</span> numberOfWheels : <span class="category1">int</span> = 2;
<span class="category1">private</span> <span class="category1">var</span> frame : Frame = <span class="category1">new</span> Frame();
<span class="category1">private</span> <span class="category1">var</span> handleBars : HandleBars = <span class="category1">new</span> HandleBars();</pre>
</code>

</div></div> 
<br/>
In the sense of an object, a variable is data that shared between the methods of an object, but encapsulated from access by external objects. In ActionScript we define variables using the keywords "private" and "var", however, a property can also be defined with the "var" keyword. It is considered a property, and not a variable, because the keyword "public" gives it public access. Properties may also be defined using <em><strong>accessor methods</strong></em>. Something we'll look at in later posts.<br/>
<br/>
A variable is simply a name that refers to a specific place in a computer's memory. A variable can have a <em><strong>value</strong></em> associated with it, and it is the variable's value that is returned when an application references a variable. A variable's value can be any sort of data, such as a whole number (int), or group of numbers or symbols (String), or even simply whether something is true or false (Boolean). One particular style of data that a variable can refer to is known as a <em><strong>primitive data type</strong></em>. There are several primitive data types that variables can represent, but to keep it simple, we'll focus on the types of data that are referred to in our Bicycle class: <em><strong>int</strong></em> and <em><strong>String</strong></em>. We also have some custom object types like HandleBars. <br/>
<br/>
Any variable that contains data that can be expressed as a whole number is of the "int" data type. The keyword "<em><strong>int</strong></em>" is what's known as a <em><strong>primitive data type</strong></em> as defined by the language specification. Data of type int refers to some whole number between -2,147,483,648 to 2,147,483,647. Our Bicycle class has several examples of variables that use the int data type, including: "numberOfWheels", "currentGear", etc. It's important to note that operations on a variable must stay consistent with that variable's data type. In the case of "int", by operations we mean tasks like addition, subtraction, multiplication, and division.<br/>
<br/>
To store information that is expressed as a collection of symbols, we use the data type String. Data that is a String (also a primitive data type), is written within quotes, such as: "thisIsAString". Any operation on data of String type returns a String. If a variable is said to be of <em><strong>String</strong></em> data type but is not assigned a value, the default value "null" is applied.<br/>
<br/>
Finally, our Bicycle class has two custom-data types: "Frame", and "HandleBars". These two custom data types suggest that the variables known as "frame" and "handlebars" are of type "Frame" and HandleBars". You'll notice that "frame" and "handlebars" are both initialized where they're declared. <br/>
<br/>
Besides being clued in by the comments, we can tell that the above code contains variables if we know a little about the naming conventions of ActionScript 3.0. A variable is declared by first setting its access to private, and then using the "var" keyword followed by the variable's name. Individual statements in ActionScript that don't include a block (additional instructions contained within curly braces), end in a semi-colon ";". Variable names, as a matter of style, start with a lower case letter, and then capitalize every subsequent word. Additionally, a variable declaration can include the data type, and possibly the initial value of the variable, as is the case with our example.<br/>
<br/>
<strong>Methods<</strong>br/>
<br/>
After the Bicycle class' variable declarations, the methods of the class are declared. <br/>
<br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="blockcomment">/**
* The following are the methods of Bicycle.
*/</span>
<span class="category1">public</span> <span class="category1">function</span> moveForward(distance:<span class="category1">int</span>=0):<span class="category1">void</span> {}
<span class="category1">public</span> <span class="category1">function</span> switchGear(selectedGear:<span class="category1">int</span>=0):<span class="category1">void</span> {}
<span class="category1">public</span> <span class="category1">function</span> stopAfterDistanceTraveled(distance:<span class="category1">int</span>=0):<span class="category1">void</span> {}</pre>
</code>

</div></div> 
<br/>
Just like the class' constructor method, these methods are declared by using the "function" keyword, followed by the method name, parameters, data types, and value. The methods listed here are of a special type known as i<em><strong>nstance methods</strong></em>. An instance method's scope is the instance of the class in which it is called. Having been declared public, these methods would welcome code from outside the class to assign values to their local variables. In our example, the local variables "distance" and "selectedGear" would receive values of type int, and Gear, respectively. Since our instance methods have a scope of the current instantiation of the Bicycle class, when outside code assigns a value to their local variable, it affects only this bicycle, and not every bicycle in the application. <br/>
<br/>
As previously mentioned, the code in our current example is an example of a single class, and shouldn't be thought of as a working application on its own. Future installments will go further into explaining the development of an application by explaining how classes interact with each other, and how to execute the code that we've written in our class. In the next few posts, we'll explain the roll of looping functions, conditionals, inherited classes, and interfaces within an application. <br/>
<br/>
<strong>The Bicycle Class Definition</strong><br/>
<br/>
 <div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="blockcomment">/**
* This syntax is used
* for comments before methods, properties, and
* class declarations.
*/</span>

<span class="linecomment">// This syntax is used for comments</span>
<span class="linecomment">// inside a method body that fit on one line.</span>

<span class="blockcomment">/* This syntax is used for multi-line
   comments inside a method body. This type
   of comment, as well as single-line
   comments, are ignored by the compiler.
   It's a good idea to make liberal use of
   comments so that your code is easier to
   follow and navigate through. */</span>

package com.mycompany.myapplication
{
 
     <span class="category1">public</span> <span class="category1">class</span> Bicycle
     {
          <span class="blockcomment">/**
           * This is the constructor method, and it is always "public".
           */</span>
          <span class="category1">public</span> <span class="category1">function</span> Bicycle( seatHeight : <span class="category1">int</span> = 0,
                                                typeOfBicycle : <span class="category2">String</span> = <span class="category1">null</span>,ﾠ
                                               totalWeight : <span class="category1">int</span> = 0,ﾠ
                                               currentGear : <span class="category1">int</span> = 0 )
          {
               <span class="category1">this</span>.seatHeight = seatHeight;
               <span class="category1">this</span>.typeOfBicycle = typeOfBicycle;
               <span class="category1">this</span>.totalWeight = totalWeight;
               <span class="category1">this</span>.currentGear = currentGear;
           }
          <span class="blockcomment">/**
           * The following are the properties of a Bicycle in the Bicycle class.
           */</span>
          <span class="category1">public</span> <span class="category1">var</span> seatHeight : <span class="category1">int</span> = 0;
          <span class="category1">public</span> <span class="category1">var</span> typeOfBicycle : <span class="category2">String</span> = <span class="category1">null</span>;
          <span class="category1">public</span> <span class="category1">var</span> totalWeight : <span class="category1">int</span> = 0;
          <span class="category1">public</span> <span class="category1">var</span> currentGear : <span class="category1">int</span> = 0;ﾠ
  
          <span class="blockcomment">/**
           * The variables of Bicycle.
           */</span>
          <span class="category1">private</span> <span class="category1">var</span> numberOfWheels : <span class="category1">int</span> = 2;
          <span class="category1">private</span> <span class="category1">var</span> frame : Frame = <span class="category1">new</span> Frame();
          <span class="category1">private</span> <span class="category1">var</span> handleBars : HandleBars = <span class="category1">new</span> HandleBars();
  
          <span class="blockcomment">/**
           * The following are the methods of Bicycle.
           */</span>
            <span class="category1">public</span> <span class="category1">function</span> moveForward(distance:<span class="category1">int</span>=0):<span class="category1">void</span> {}
            <span class="category1">public</span> <span class="category1">function</span> switchGear(selectedGear:<span class="category1">int</span>=0):<span class="category1">void</span> {}
            <span class="category1">public</span> <span class="category1">function</span> stopAfterDistanceTraveled(distance:<span class="category1">int</span>=0):<span class="category1">void</span> {}
      }
}</pre>
</code>

</div></div> 
<br/>
<strong>Glossary of Terms</strong><br/>
 <br/>
// The symbols in ActionScript that signal the beginning of a single line comment.
<br/>
/* */ Symbols in ActionScript that surround a multi-line comment.
<br/>
<strong>:</strong>A symbol ActionScript uses as part of a variable declaration that separates a variables name from it's type.<br/>
<br/>
<strong>Application</strong> A computer programﾠ<br/>
<br/>
<strong>Attribute</strong> In ActionScript 3.0, an attribute is any member of a class that is a variable or is defined by a getter or setter method. examples include:<br/>
public, private, protected, static, internal, and UserDefinedNamespace.<br/>ﾠ
<br/>
<strong>Best Practices</strong> Rules of convention that, when followed, produce elegant code.<br/>
<br/>
<strong>Block Statement</strong> A collection of directives located within curly braces.<br/>
<br/>
<strong>Body</strong> In ActionScript, the instructions for classes and its members that are placed within curly braces.<br/>
<br/>
<strong>Comment</strong> Text within source code that is not read by the compiler, and
is there for the purpose of maintaining organization and providing clarity.<br/>
<br/>
<strong>Constructor</strong> See "Constructor Method".<br/>
<br/>
<strong>Constructor Method</strong> A specific method within a class that defines the
instantiation of an object from the class. Constructor methods are always declared public, and are named after their class.<br/>
<br/>
<strong>Custom Data Type</strong> See "Object Data Type".<br/>
<br/>
<strong>Data Type</strong> The specific category in which a variable's data resides. A whole number, for example, is a different data type (int) than a word (String).<br/>
<br/>
<strong>Declare</strong> The act of including in your source code the methods, properties, parameters, classes, etc that belong to a class.<br/>
<br/>
<strong>ECMA-262</strong> The language specification outlined by ECMA International that determines the syntax and rules of best practices of ActionScript 3.0.<br/>
<br/>
<strong>ECMA</strong> International The international private standards organization that created ECMA-262, and thus ECMAScript.<br/>
<br/>
<strong>ECMAScript</strong> The scripting language created by ECMA International and defined by the ECMA-262 specification from which ActionScript 3.0 was modeled.<br/>
<br/>
<strong>Function</strong> A set of instructions to be carried out by a program. In ActionScript are two types of functions: methods, and function closures. A method is a function defined within a class definition, or attached to an object, and a function closure is defined anywhere else.<br/>
<br/>
<strong>Import</strong> An ActionScript keyword that is used to bring a class declaration into another package.<br/>
<br/>
<strong>Instance Methods</strong> Methods of a class whose scope is a particular instance of that class.<br/><br/>
<strong>int</strong> A keyword in ActionScript that defines a variable's data type as being a whole number.<br/><br/>
<strong>JavaScript</strong> A scripting language originally developed by Brendan Eich of Netscape. JavaScript was the first dialect of the ECMA-262 specification.<br/>
<br/>
<strong>JScript.NET</strong> Scripting language developed by Microsoft that, like ActionScript, follows the ECMA-262 language specification.<br/>
<br/>
<strong>Keyword</strong> Those words that are reserved by the language and that alert the compiler about some important information. For example, the "new" keyword signals the compiler that an object is being instantiated.<br/>
<br/>
<strong>Legal</strong> The term used to refer to source code that will compile without errors.<br/>
<br/>
<strong>Local Variable</strong> A variable who's scope includes a specific part of an application.<br/>
<br/>
<strong>Main Class</strong> A program's point of entry. Always declared public, the main class allows the compiler to access the rest of the program.<br/>
<br/>
<strong>Method Parameters</strong> Local variables that are included as a part of a method definition. <br/>
<br/>
<strong>null</strong> A data type that has only one value; null, or "no value". null is the default value for variables of String data type, as well as complex data types such as the Object data type.<br/>
<br/>
<strong>Object Data Type</strong> A data type that all complex data types stem from.<br/>
<br/>
<strong>Operand</strong> A value that an operator uses as input.<br/>
<br/>
<strong>Operator</strong> A function that uses one or more operands together to return a value. Such as: 2 + 2 = 4.<br/>
<br/>
<strong>Package</strong> A conceptual container in which to place an applications related classes. A class within a package takes on the package name as part of its name and therefore creates a unique namespace for the class to reside in.<br/>
<br/>
<strong>Primitive Data Type</strong> Special data types specified by the language used to represent variables of type: int, Boolean, String, null, Number, uint, and void.<br/>
<br/>
<strong>Scope</strong> The part of an application that is accessible to the members of a class.<br/>
<br/>
<strong>Statement</strong> A basic program instruction or directive.<br/>
<br/>
<strong>Static</strong> In ActionScript, methods and variables declared as static are accessible at the class level only.<br/>
<br/>
<strong>String</strong> A primitive data type that represents values expressed in textual form, such as a string of letters in a word.<br/>
<br/>
<strong>Syntax</strong> The grammatical and structural rules governing the use of symbols and terms within source code.<br/>
<br/>
<strong>this</strong> A keyword in ActionScript that is used to refer to the current instance of a class.<br/>
<br/>
<strong>Uniform Resource Locator (URL)</strong> A compact string of characters that are used to locate documents on the web. Guaranteed unique by the World Wide Web Consortium, URLs make good candidates for package names, which require unique identities.<br/>
<br/>
<strong>Value</strong> The specific data associated with a variable.<br/>
<br/>
<strong>var</strong> The keyword that tells the compiler to reserve space in memory for a value. In other words, it cues the declaration of a variable.<br/>
<br/>
<strong>W3C</strong> The World Wide Web Consortium. The main international standards commission for the world wide web. 

<p>
Next: <a href="http://www.insideria.com/2008/03/lffs5actionscript-conditionals.html">LFFS - 5: ActionScript 3.0 - Conditionals and Loops</a>
</p>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-3756476-8";
urchinTracker();
</script>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23101-comment:2015837</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23101" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html#comment-2015837" />
    <title>Comment from Peter Martin on 2008-03-13</title>
    <author>
        <name>Peter Martin</name>
        <uri>http://cairlinn.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://cairlinn.com">
        <![CDATA[<p>great series of articles to all learning OO principles and actionscript.<br />
keep it up</p>]]>
    </content>
    <published>2008-03-13T17:53:05Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23101-comment:2015840</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23101" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html#comment-2015840" />
    <title>Comment from Scott on 2008-03-13</title>
    <author>
        <name>Scott</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>@Peter Martin</p>

<p>Thanks Peter!  Our plan for the next few installments is to keep it a little shorter/more focused.  We'll be checking out the role loops play next. Thanks for reading!</p>]]>
    </content>
    <published>2008-03-13T18:28:14Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23101-comment:2016132</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23101" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html#comment-2016132" />
    <title>Comment from Hyrum Tanner on 2008-03-25</title>
    <author>
        <name>Hyrum Tanner</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>This syntax</p>

<p>public function moveForward( distance : int )= 0 {}</p>

<p>doesn't look right to me. What exactly is that function doing? Did you mean to put</p>

<p>public function moveForward(distance:int = 0):void {}</p>

<p>?</p>]]>
    </content>
    <published>2008-03-25T20:06:32Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23101-comment:2016150</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23101" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html#comment-2016150" />
    <title>Comment from Scott on 2008-03-26</title>
    <author>
        <name>Scott</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>@Hyrum:</p>

<p>You're correct Hyrum, and we apologize for the error.  We're working at make the correction, and we appreciate the observation!</p>]]>
    </content>
    <published>2008-03-26T16:49:17Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23101-comment:2016151</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23101" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html#comment-2016151" />
    <title>Comment from Scott on 2008-03-26</title>
    <author>
        <name>Scott</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>(making)  ;)</p>]]>
    </content>
    <published>2008-03-26T16:51:21Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23101-comment:2049711</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23101" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/03/lffs-4-actionscript-30.html#comment-2049711" />
    <title>Comment from Anonymous on 2008-12-27</title>
    <author>
        <name>Anonymous</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>//class MouseUtils<br />
package alternativa.utils <br />
{<br />
    import flash.display.*;<br />
    import flash.geom.*;<br />
    <br />
    public class MouseUtils extends Object<br />
    {<br />
        public function MouseUtils()<br />
        {<br />
            super();<br />
            return;<br />
        }</p>

<p>        public static function init(globalToLocal:flash.display.Stage):void<br />
        {<br />
            var loc1:*;</p>

<p>            _stage = loc1;<br />
            return;<br />
        }</p>

<p>        public static function localCoords(stageWidth:flash.display.DisplayObject):flash.geom.Point<br />
        {<br />
            var loc1:*;</p>

<p>            return loc1.globalToLocal(globalCoords());<br />
        }</p>

<p>        public static function globalCoords(Object:Boolean=true):flash.geom.Point<br />
        {<br />
            var loc1:*;<br />
            var loc2:*;<br />
            var loc3:*;<br />
            var loc4:*;</p>

<p>            loc3 = 0;<br />
            loc4 = 0;<br />
            loc2 = null;<br />
            if (_stage == null)<br />
            {<br />
                throw new Error("MouseUtility don\'t have link to stage. Use MouseUtility.init(stage) before.");<br />
            }<br />
            else <br />
            {<br />
                loc3 = _stage.mouseX;<br />
                loc4 = _stage.mouseY;<br />
                if (loc1)<br />
                {<br />
                    loc3 = (loc3  _stage.stageWidth) ? _stage.stageWidth : loc3;<br />
                    loc4 = (loc4  _stage.stageHeight) ? _stage.stageHeight : loc4;<br />
                }<br />
                loc2 = new Point(loc3, loc4);<br />
            }<br />
            return loc2;<br />
        }</p>

<p>        <br />
        {<br />
            _stage = null;<br />
        }</p>

<p>        private static var _stage:flash.display.Stage=null;<br />
    }<br />
}</p>]]>
    </content>
    <published>2008-12-28T07:50:01Z</published>
  </entry>

</feed
