Yes I thought that would fix the problem so I tried implementing this
within the
function notifyPropertyChange method
private function
notifyPropertyChange(name:String,oldValue:Object,value:Object):void
{
if (value !== oldValue)
{
var event:PropertyChangeEvent = new
PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE,
true,false,"update",name,oldValue,value,this);
dispatchEvent(event);
}
}
Now in the main.mxml file, I've set the listener like this:
this.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,testTrace,true\
);
I can never seem to get this event to be recognized by the application.
For reference, this notifyPropertyChange method is contained within an
AS class that fires the event when a Timer event fires after 1 minute.
At this point, a new Date object is created, compared with the old date
value and fires the notifyPropertyChange method, to update the onscreen
time display.
If I register a listener with the target, then I can receive the event.
But I cannot seem to get any event, particularly the PROPERTY_CHANGE
event, which is what I want.
I'd love to be able to use the propertychangeevent cuz it seems like a
nice, subtle way to be alerted of changes to an instance's variable. Any
suggestions on how to use the PropertyChangeEvent properly?? :)
regards
erick
--- In [email protected], "valdhor" <[EMAIL PROTECTED]> wrote:
>
> I had the same sort of problem and found that I forgot to set the
> "bubbles" property of my custom event to true (It is false by
default).
>
>
> --- In [email protected], "superbokbok" <superbokbok@> wrote:
> >
> > I'm building a simple app and trying to get the PropertyChangeEvent
to
> > work properly as an alternative to using an explicit eventDispatch
call.
> > I can't seem to get the updated variable to be recognized by the
main
> > apps component.
> >
> > In my AS3 class I have set the class to [Bindable] so that all the
> > properties can be bound to the appropriate controls in the main.mxml
> > file. I've used this import to bring in the PropertyChangeEvent:
> > import mx.events.PropertyChangeEvent;
> > A timer fires from the main.mxml file and calls the setLastChecked
> > function passing in a new Date object(new Date()) to trigger the
update
> > of the variable like this:
> >
> > private function setLastChecked(value:Date):void
> > {
> > var oldValue:Object = _lastChecked;
> > _lastChecked = value;
> >
> > notifyPropertyChange("lastChecked", oldValue, value);
> > }
> >
> >
> > private function
> > notifyPropertyChange(name:String,oldValue:Object,value:Object):void
> > {
> > if (value !== oldValue)
> > {
> >
> > dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, name,
> > oldValue, value));
> > }
> > }
> >
> > The variable "lastChecked" is bound to a textfield in the main.mxml
file
> > like so:
> >
> > <mx:Text
> > text="{formatDate(subscriptionsList.selectedItem.lastChecked)}"/>
> > which formats the data as a string to display the date.
> >
> > The problem is that the variable is never updated on screen. I've
been
> > able to confirm that the event from the timer fires, triggers the
> > notifyPropertyChange event but that event is never received from the
> > Text component or received within the main.mxml app.
> > Is there something I'm missing throughout this process or need to
add to
> > get the event recognized in the main app??!!
> >
>