Indexed Array in AS3


 

Indexed Array in AS3

If user want to store multiple value in a single data structure then it can be used Array for this process.

If user want to store multiple value in a single data structure then it can be used Array for this process.

Indexed Array in Action Script3:-

If user want to store multiple value in a single data structure then it can be used Array for this process. Indexed array is a type of it. Indexed array provides you to store a collection of one or more then one value. It is used unsigned integer value for access each value of the indexed array. The first index of the indexed array is always number 0 and increase by 1 for each value added in the array. The indexed arrays used two classes : the Array class and the Vector class.

Array Class example:-

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init();">

<fx:Script>

<![CDATA[

import mx.controls.Alert;

import mx.controls.Text;

public function init():void{

var cities:Array = new Array("Kanpur", "Delhi", "Aligarh", "Jaipur", "Mumbai");

for(var i:uint = 0; i<cities.length; i++){

var text:Text = new Text();

text.text = cities[i];

myVBox.addElement(text);

}

}

]]>

</fx:Script>

<s:Panel width="160" height="170" title="Array Class example" backgroundColor="0xEEFFEE">

<s:VGroup id="myVBox">

</s:VGroup>

</s:Panel>

</s:Application>

Array class instance can hold  different types of data type. In this example, we have used Array class instance that hold string type cities name after that we have accesses it.

Output:-

Download this code

Ads