PDA

View Full Version : addEventListener(PropertyChangeEvent.PROPERTY_CHAN GE !?!?!


BrettAF3D
06-06-2008, 01:30 AM
I want to set a data Obj on my MenuItemMC with an eventListener to automatically Refresh() my content when the data updated....

Is there a way to be notified by an event like:
_data.addEventListener(Event.CHANGE, Refresh);
or
var p:ObjectProxy = new ObjectProxy(_data);
p.addEventListener(PropertyChangeEvent.PROPERTY_CH ANGE, Refresh);

in flash ??? this would be GREAT !!!!

lordofduct
06-06-2008, 01:33 AM
yeah, in the class for the object that is being updated, dispatch an event when a property changes via its getter/setter methods.

BrettAF3D
06-06-2008, 01:50 AM
Thanks for your interest ...


public function set data(value:Object):void
{
_data = value;
}

public function get data():Object
{
return _data;
}

public function Refresh()
{
if(_data.$title)
{
titleTXT.text = _data.$title;
}
}


I would like to leave the set data() method as is cause if i am to add a dispatch event to it i might as well just add a call to Refresh(); What do you think ?

amarghosh
06-06-2008, 05:52 AM
if refresh method is in the same class and u need to refresh for every objects (if u r not selective about refreshing) u can call refresh directly from the setter. event mechanism is useful if u don't want all objects to be refreshed or refreshing is done in some another class.
if u don't wanna modify the setter at all .... i don't know if there is a way

pj-co
06-06-2008, 07:10 AM
yep agree with the above posters: just add an event dispatch to the setter, or call refresh to send the dispatch.

it sounds like just what you need

BrettAF3D
06-07-2008, 07:09 PM
OK i get what you are saying but the fact that i cannot set an event listener "Change" to a property (what ever it may be) in FLASH is FRUSTRATING !!!!

I would even consider it as being a fundamental need...

lordofduct
06-08-2008, 03:35 AM
having all objects dispatch events every time a property is changed would cause for a lot of slow down. I mean consider the idea that that you have a variable that you reuse over and over and over in loops and all over the place. Every time you accessed it, this event would fire.

On top of that, consider things like all the C languages, they hardly use eventDispatchers. And everyone has gotten by with out it. (Yes there are event style handling in things like C#, but it isn't quite like AS3's eventDispatcher).

This is why the getter and setter methods are available to you. It isn't like it's that hard to just stick another call to a method inside of these methods. It gives you, the programmer, much more ease of control.


Keep in mind, proper OO standards suggest that you always protect properties and use getter and setter methods to change them.

BrettAF3D
06-08-2008, 03:10 PM
thanks you for your thoughts on this i appreciate... The way i am thinking of it is not in relation to the event dispatcher framework available its more about the monitoring of a property... it would be more like subscribing to a list that get there value monitored at a low level to save on processing power... and in regards to OOP practice the idea of leaving a set property as an set property and nothing more attracts me... I think this system is implemented in FLEX with the ( addEventListener(PropertyChangeEvent.PROPERTY_CHAN GE )so really its only a mater of time to get it available in FLASH but its still frustrating not to have any other alternative than to set an event enterframe (costly to the CPU) to monitor the fluctuation of a property...