Bindable on event
Hi,
I'm trying to get a timer event to update an internal variable in a class accessible through bindable getter, but it's not working. The timer event fires, I can see this in debug mode but apparently the change propagation through binding on the event doesn't work. I've been staring at this for half an hour and would really like to know what I'm doing wrong, if you have an idea please let me know.
This is my class:
package managers
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.utils.Timer;
[Bindable]
public class TestEventBinding extends EventDispatcher
{
public static const MYEVENT:String = "myevent";
public function TestEventBinding()
{
super();
refreshTimer.addEventListener(TimerEvent.TIMER, refreshTimerHandler);
refreshTimer.start();
}
private function refreshTimerHandler(event:TimerEvent):void {
//myNum++;
myNum = myNum + 1;
}
[Bindable(event=MYEVENT)]
public function get myNum():int {
return _myNum;
}
[Bindable(event=MYEVENT)]
public function set myNum(num:int):void {
_myNum = num;
dispatchEvent(new Event(MYEVENT));
}
private var _myNum:int = 0;
private var refreshTimer:Timer = new Timer(1000);
}
}
And this sample application mxml:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
>
<mx:Script>
<![CDATA[
import managers.TestEventBinding;
private var test:TestEventBinding = new TestEventBinding();
]]>
</mx:Script>
<mx:NumericStepper minimum="0" maximum="1000" value="{test.myNum}"/>
/>
I get the warning: assignment to test cannot be detected, which I don't understand, I have a getter and setter but on test.myNum. For now I don't want to bind for assignment, just getting the value and update the control based on some event which is internal to the class (in this example a timerevent).
Anybody that can see what I do wrong I would be very grateful for the solution.
Thanks alot
Frederik
