[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Flex 2.1 ChangeWatcher working only once

Posted on 2011-03-22
1
Medium Priority
?
499 Views
Last Modified: 2012-05-11
I have been working with flex 2.1 for a while now and have recently used the ChangeWatcher for finding out when the value of the variable changes.

The handler is getting invoked once when the value is getting changed. But for subsequent changes, I believe the handler is not being called.

My code is something as follows:

Could someone please advice as to what could be going wrong?

File:Caller.mxml(it is a popup screen)

//in mx:Script

private var watch:ChangeWatcher = ChangeWatcher.watch(a,"numberOfItems",updateScreen);

private function updateScreen(event:Event):void{
Alert.show(a.numberOfItems);

Open in new window

File: A.as

[Bindable] public var numberOfItems:int;

Open in new window

0
Comment
Question by:Chikithegreat
1 Comment
 
LVL 29

Accepted Solution

by:
dgofman earned 200 total points
ID: 35192924
Workd for me, only exception when you may not get fire event is assigning value is the same as exisitng numberOfItems, in this cse you should create a setter and dispatchEvent manually or temporary assign to -1 or some other number

Main.mxml

<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" width="100%" height="100%" initialize="init()" xmlns:projectWork="*">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.binding.utils.ChangeWatcher;
			import mx.controls.Alert;
			

			private var a:A = new A();
			private var watch:ChangeWatcher = ChangeWatcher.watch(a,"numberOfItems", updateScreen);
			
			private function updateScreen(event:Event):void{
				Alert.show(String(a.numberOfItems)); 
			}
		]]>
	</fx:Script>
	<s:Button label="Increment" click="a.numberOfItems++"/>
</s:Application> 

Open in new window



A.as

package
{
	public class A
	{
		[Bindable]
		public var numberOfItems:int = 0; 
	}
}

Open in new window

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question