Home » Uncategorized

ActionScript Basics part 4

24 November 2010 No Comment
Share on Facebook

Previous Entries:
ActionScript basics part1

ActionScript basics part2

ActionScript basics part3

ActionScript basics part4

ActionScript basics part5

ActionScript basics part6

In this tutorial we are going to explore Array which is available in most of the programming languages.

What is an Array?

  • Array is used to hold collection of data or list of values of same datatype.
  • Array has many buitin functions to manipulate the values it holds.
  • An array data can be accessed at anytime using array index.

Creating an Array

To create an array, declare a variable of type Array and declare the new Array object.

var arrObject:Array = new Array();

There is another way of of creating an array using square brackets that called array literal.

var arrObject:Array = [];

Similar we cab have values in Array when we create it.

var arrObject:Array = ["Sara","Santha","Subha","Ranja"];

Accesing a value using index

Array value can be accessed using index of an array, Array index always starts with value 0.

To access the value Sara from the above Array.

trace( arrObject[0] );

Adding a value in Array

A value can be added in array using the push method of an Array. push method adds value at end of an Array

var arrObject:Array = ["Sara","Santha","Subha","Ranja"];
arrObject.push( "Bas" );

Remove a value from an Array

A value can be removed from an Array using pop method of an Array.
pop method removes value at the end of an Array.

var arrObject:Array = ["Sara","Santha","Subha","Ranja"];
arrObject.pop( );

Find length of an Array

An useful method of an Array to manipulate with it.
The length method of the array returns how elements contained in an Array.

var arrObject:Array = ["Sara","Santha","Subha","Ranja"];
trace( arrObject.length() )
//Returns 3

The length returns the total index value.

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner