Solved

Flex 2.1 ChangeWatcher working only once

Posted on 2011-03-22
1
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 29

Accepted Solution

by:
dgofman earned 50 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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

Suggested Solutions

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…
Changing a few Outlook Options can help keep you organized!
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

737 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