5/24/10

Simple example for Change Watcher

Change Watcher actually watches for the change in the variable. For example we shall assume a variable name
myChange and its data-type is integer. it takes one as its value .  we can use the change watcher method to read the changes in the mychange variable.
Note : changed value must not be one here for the variable. because one has already been assigned to it.

Following is the example for ChangeWatcher using array collection


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()" layout="absolute">

<mx:Script>

<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.binding.utils.ChangeWatcher;
import mx.collections.ArrayCollection;


private function init():void
{
mx.binding.utils.ChangeWatcher.watch(tester,"length",myNotify);

}

private function myNotify(event:Event):void
{

Alert.show("Array Altered!");

}

private function pushOne():void
{

tester.addItem({label:"Item", data:"Item"});

}

]]>
</mx:Script>

<mx:ArrayCollection id="tester">
<mx:Object label="Item" data="Item"/>
<mx:Object label="Item" data="Item"/>
<mx:Object label="Item" data="Item"/>
<mx:Object label="Item" data="Item"/>
</mx:ArrayCollection>

<mx:ComboBox id="foo" dataProvider="{tester}" horizontalCenter="0" verticalCenter="-114.5"/>


<mx:Button label="Add One Item" click="pushOne()" horizontalCenter="0" verticalCenter="121.5"/>
</mx:Application>

No comments:

Post a Comment

Popular Posts