Solved

Flex 2.1 ChangeWatcher working only once

Posted on 2011-03-22
1
456 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 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check for non negative number 2 442
displaying tif image on flex side 1 304
Flex mobile local storage. 2 627
how can i learn adobe flex step by step 4 97
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…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now