Defining Arrays for style properties using Action Script in Flex 4

February 2nd, 2011 by aabhaanjan

We can define the Array in AS by using a comma-separated list of values surrounded by braces.

Example :

[xml]

<?xml version=”1.0″?>

<s:Application

xmlns:fx=”http://ns.adobe.com/mxml/2009″

xmlns:mx=”library://ns.adobe.com/flex/mx”

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

creationComplete=”initApp()”

height=”500″>

<fx:Script>

<![CDATA[

public function initApp():void {

tree1.setStyle(“depthColors”,[0xFF3300, 0xFFCC99, 0xCC9900]);

tree1.setStyle(“alternatingItemColors”,[“red”, “green”]);

}

]]>

</fx:Script>

<fx:Declarations>

<fx:XMLList id=”treeData”>

<node label=”Node 1″>

<node label=”subnode 1″>

<node label=”label 1″/>

<node label=”label 2″/>

<node label=”label 3″/>

</node>

<node label=”subnode 2″>

<node label=”label 1″/>

<node label=”label 2″/>

</node>

</node>

</fx:XMLList>

</fx:Declarations>

<s:Panel title=”Style Array using Action Script” width=”100%”>

<s:layout>

<s:VerticalLayout/>

</s:layout>

<mx:Tree id=”tree1″

width=”100%”

labelField=”@label”

dataProvider=”{treeData}”/>

<mx:Tree id=”tree2″

width=”100%”

labelField=”@label”

dataProvider=”{treeData}”

depthColors=”[0xFFCC33, 0xFFCC99, 0xCC9900]”

alternatingItemColors=”[‘red’, ‘green’]”/>

</s:Panel>

</s:Application>

[/xml]

Tags: ,