Solved

Flex 2.1 ChangeWatcher working only once

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Highlight/Sticky Note/Bookmark page - SWF file 9 348
AdvancedDataGrid 5 522
Sum column DataGrid 3 576
Facebook Flash API - How do you edit MobileLoginWindow.as? 4 757
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…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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