Array Declaration

The Array class lets you access and manipulate arrays. Array indices are zero-based, which means that the first element in the array is [0], the second element is [1], and so on.

Different Way of Declaring and storing Arrays

First Method

var Ar:Array=new Array()
trace(Ar) // Returns Orange, Apple
trace(Ar[0]) //Returns Orange

Second Method

var Ar:Array=new Array(“Orange”,”Apple”)
trace(Ar) // Returns Orange, Apple
trace(Ar[0]) //Returns Orange

Third Method

var Ar:Array=new Array()
trace(Ar) //Orange, Apple

Fourth Method

var Ar:Array=new Array()
trace(Ar) // Orange, Apple

Fifth Method

var Ar=[]
trace(Ar) // Orange, Apple

Get Unique values from Array

This can be achieved (in AS2 and AS3) in a much simpler manner, using the following function or prototype:

Array.prototype.countValues = function ()
var z, x = this.length, c = false, a = [], d = [];
while (x–) { z = 0;  while (z < x){ if (this[x] == this[z]){ c = true; d.push (this[x]); break; }
z++;} if (!c) a.push ([this[x], 1]); else c = false; } y = a.length;while (y–) { q = 0; while (q < d.length) { if (a[y][0] == d[q]) a[y][1]++; q++; }}
return a;

For an example i have an array [“Orange”,”Apple”,”Apple”,”Orange”,”Pappaya”],
Would like to get the count of each values [Orange => 2, Apple => 2, Pappaya

Once the following function is invoked for this array, it removes the all the
duplicates and generate a new Array with Unique values and it counts.


var SourceArray=[“Orange”,”Apple”,”Apple”,”Orange”,”Pappaya”]
var NewArray=SourceArray.countValues()
trace(NewArray)//Returns Pappaya,1,Apple,2,Orange,2

Access SharePoint list in Flex

Simply put together the link as below.


How to get GUID for List  

1. Site Actions -> Site Settings

2. Click on Site Libraries and lists on the list which you would like to access as XML.

4. Get the List ID from the Redirected URL


6. XML Output

How to read SharePoint List from Flex 

<?xml version=”1.0″ encoding=”utf-8″?><mx:Application xmlns:mx=”” layout=”absolute”
import mx.controls.Alert;
private function onCreate(e:Event):void
var XMLLoader:URLLoader=new URLLoader(new URLRequest(“http://[localHost]/_vti_bin/owssvr.dll?Cmd=Display&List={80D18622-447F-4900-90A5-E424EDB95DCD}&XMLDATA=TRUE”))
function openXMLValues(e:Event):void
var XMLL:XMLList=new XMLList(
var rsNS:Namespace = XMLL.namespace(“rs”);// Create Namespace inorder to access the XML node <rs:>
var zNS:Namespace = XMLL.namespace(“z”);// Create Namespace inorder to access the XML node <z:
var sNS:Namespace = XMLL.namespace(“s”); // Create Namespace inorder to access the XML node <s:
var FinalXML:XMLList=new XMLList(XMLL.rsNS::data.zNS::row) // access the node <rs:row>


The URLLoader class downloads data from a URL as text, binary data, or
URL-encoded variables. It is useful for downloading text files, XML, or other
information to be used in a dynamic, data-driven application.

var XMLLoader:URLLoader=new URLLoader(new URLRequest(“http://[localHost]/_vti_bin/owssvr.dll?Cmd=Display&List={80D18622-447F-4900-90A5-E424EDB95DCD}&XMLDATA=TRUE“))



The XMLList class contains methods for working with one or more XML elements. An
XMLList object can represent one or more XML objects or elements (including
multiple nodes or attributes), so you can call methods on the elements as a
group or on the individual elements in the collection.

var XMLL:XMLList=new XMLList(

XMLL will have the entire XML elements including all attributes and nodes.

RecordSet XML vs Normal XML  

RecordSet XML

<xml xmlns:s=’uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882′ xmlns:dt=’uuid:C2F41010-65B3-11d1-A29F-00AA00C14882′xmlns:rs=’urn:schemas-microsoft-com:rowset’ xmlns:z=’#RowsetSchema’>
<s:Schema id=’RowsetSchema’>
<s:ElementType name=’row’ content=’eltOnly’ rs:CommandTimeout=’30’>
<s:AttributeType name=’ID’ rs:number=’1′>
<s:datatype dt:type=’int’ dt:maxLength=’4′ rs:precision=’10’ rs:fixedlength=’true’ rs:maybenull=’false’/>
<s:AttributeType name=’c1′ rs:name=’Status Code’ rs:number=’2′rs:writeunknown=’true’>
<s:datatype dt:type=’string’ dt:maxLength=’20’ rs:fixedlength=’true’ rs:maybenull=’false’/>
<s:extends type=’rs:rowbase’/>
<rs:data><z:row ID=’1′ c1=’Add ‘/>
<z:row ID=’2′ c1=’Drop ‘/>
<z:row ID=’3′ c1=’Modify Date ‘/>
<z:row ID=’4′ c1=’Complete ‘/>
<z:row ID=’5′ c1=’Modify Parameters ‘/>

In order to access <z:row> recordset, you need to create Namespace for z: , rs:
, s: ,etc..,

var XMLL:XMLList=new XMLList(
var rsNS:Namespace = XMLL.namespace(“rs”);// Create Namespace inorder to access
the XML node <rs:>
var zNS:Namespace = XMLL.namespace(“z”); // Create Namespace inorder to access the XML node <z:
var sNS:Namespace = XMLL.namespace(“s”); // Create Namespace inorder to access the XML node <s:
var FinalXML:XMLList=new XMLList(XMLL.rsNS::data.zNS::row) // access the node <rs:row>

Normal XML

<xml >
<row ID=’1′ c1=’Add ‘/>
<row ID=’2′ c1=’Drop ‘/>
<row ID=’3′ c1=’Modify Date ‘/>
<row ID=’4′ c1=’Complete ‘/>
<row ID=’5′ c1=’Modify Parameters ‘/>

var XMLL:XMLList=new XMLList(
var FinalXML:XMLList=new XMLList(

Find and replace in ActionScript

Here i have given two functions

  • Find – Checks whether the string holder contains the word and returns true or false
  • FindAndReplace – Checks for the string and replace with the new word provided.

var Str=“i love blogging”
(“result —>” +out)
(“result1 —->”+out1)

function Find(SourceStr, FindString) :Boolean
var NArray=SourceStr.split(FindString)
return true

return false

function FindAndReplace(SourceString, FindString,ReplaceString) :String
var SplitArray=SourceString.split(FindString)
var Result=SplitArray.join(ReplaceString)

Save File in Adobe Flex -AIR

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”” layout=”absolute” creationComplete=”onCreate(event)”>
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
function onCreate(e:Event):

var file:File = File.desktopDirectory; //Set the Directory location to Desktop
file = file.resolvePath(
“test.txt); //File Name
fileStream:FileStream = new
FileStream();   // Create new FileStream to Perform Read or Write, FileMode.WRITE); // Open file in WRITE Mode
“Hello World”); //Write Hello World into test.txt
fileStream.close(); //Close the File Stream


This code creates a file named test.txt with content “Hello World” in desktop folder.

The desktopDirectory property provides a way to reference the desktop directory that works across platforms. If you set a File object to reference the desktop directory using the nativePath or url property, it will only work on the platform for which that path is valid Similarly documentDirectory /applicationStorageDirectory /applicationDirectory can be used to represent the folder.

var file:File = new File();
file = file.resolvePath(

This will work in windows platform and stores file in user mentioned location.

Accessing SharePoint List as XML

1. Returning all data for a SharePoint list,
including its XSD –http://[localhost]/_vti_bin/owssvr.dll?Cmd=Display&amp;List={ListGuid}&amp;Query=*&amp;XMLDATA=TRUE

2.Rreturning data of SharePoint list based on a specific view from the list –http://[localhost]/_vti_bin/owssvr.dll?Cmd=Display&amp;List={ListGuid}&amp;View={ViewGuid}&amp;XMLDATA=TRUE

3.Returning List definition – http://[localhost]/_vti_bin/owssvr.dll?Cmd=ExportList&amp;List={ListGuid}

4. Retrieving ONET.XML – http://[localhost]/_vti_bin/owssvr.dll?Cmd=GetProjSchema

5. Retrieving field types – http://[localhost]/vti_bin/owssvr.dll?Cmd=GetProjSchema&amp;SiteTemplate=fldtypes