Home » ActionScript 3.0

Introduction to AS3 – Part1

30 October 2008 12 Comments

ActionScript is the programming language for Flash Player run-time environment.

ActionScript3.0 is the newer version of ActionScript. AS3 runs in Virtual Machine AVM2 which provides significant improvement in the performance.

With improved API AS3 is based on ECMAScript.

An event model based on the Document Object Model (DOM) Level 3 Events Specification.

Some of the Important Core language features includes

· ECMAScript for XML (E4X)

· Regular Expressions

· Namespaces

· New Primitive types

E4X for XML:

The ECMAScript for XML specification defines a set of classes and functionality for working with XML data. These classes and functionality are known collectively as E4X.

Example of XML:

<store>
<item id=’1′>
<name>Bag</name>
<price>300</price>
</item>
<item id=’2′>
<name>Pencil</name>
<price>5</price>
</item>
<item id=’3′>
<name>Chocolate</name>
<price>10</price>
</item>
</store>

We are not going to discuss more about XML here..

E4X contains (.)dot operators and (@) attribute identifier for accessing the properties and attributes in XML.

Lets see some in action

Create a new flash document in Flash CS3.

And type.

var store:XML = <store>
<item id=’1′>
<name>Bag</name>
<price>300</price>
</item>
<item id=’2′>
<name>Pencil</name>
<price>5</price>
</item>
<item id=’3′>
<name>Chocolate</name>
<price>10</price>
</item>
</store>

trace(store.item.(@id==2).price)//outputs 5

trace(store.item[2].name)//outputs Chocolate

trace(store.item.(name == “Bag”).price)//outputs 300

Here,

. and @ operators used to manipulate the XML Data.

XMLList is the XML document without root node.

In the above XML example the XMLList is XML elements without rootnode store.

<item id=’1′>
<name>Bag</name>
<price>300</price>
</item>
<item id=’2′>
<name>Pencil</name>
<price>5</price>
</item>
<item id=’3′>
<name>Chocolate</name>
<price>10</price>
</item>

trace(store.item.(price <= 10).name)

//outputs : <name>Pencil</name><name>Chocolate</name>

// which is an XMLLIst

From the above we can understand that using E4X we can write conditional statements to access the XML.

We can also loop through the XML using For Each loop.

for each( var item:XML in store.item)

trace(item.(@id).price)

//outputs 300 5 10

Regular Expressions:

Regular Expression (regex) are to match particular and manipulate text in a sting.

For example Regular Expressions can be used to find text pattern in a string. Like validating email, numeric inputs..

Regular Expressions in AS3 are written in native code.

Regular expression should be written within backlash characters.

To find set of characters present in the string we use

[0-9] indicates numbers 0 to 9, [a-b] indicates characters [a-z].

We can also use shorthand notations like

\d for numbers 0-9

\w for characters a-z also includes underscore(_)

\s for space characters.

Sample:

//To check a given input is number

var regexp:RegExp = /^(0|[1-9][0-9]*)$/;

trace(regexp.test(”65645673″));

//outputs true since contains only number

trace(regexp.test(”Designscripting.com”));

//outputs false

Here little explanation fo the regex used above.

the number should be zero or numbers from one.

* used for matching one or more matches,

$ used for matching at the end of the String.

Some of the regular expressions available

http://www.rgagnon.com/jsdetails/js-0063.html

Namespaces:

We are going to discuss about namespaces in upcoming sections.

New Primitive Type:

Some of new datatypes included in ActionScript 3.0 are int and uint.

Uint datatypes can be used to hold the color values.

Int datatype is 32 bit signed integer and ActionScript code use faster math capability of CPU. Int datatype can be used in loop counters for fast math calculations.

Note:

Int(number) is there from flash 5 but used for converting decimal numbers to number.

Sample:

//uint datatype can be used to hold color values.

var _colorvalue : uint = 0×990000;

//int variables can be used for loop counters.

for( var i : int; i < 10; i++)

trace(”i::”,i);

Â

Now its time to learn Introduction to AS3.0 part2Â

Download Source Files

Â

  • Share/Bookmark

Related posts:

  1. XPathAPI – Actionscript 2.0
  2. Introduction to actionscript3.0 part3
  3. Introduction to AS3 – Part2

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.