Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-06-2008, 02:30 AM   #1
BrettAF3D
Member
 
Join Date: Jul 2005
Posts: 86
Default addEventListener(PropertyChangeEvent.PROPERTY_CHAN GE !?!?!

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 !!!!
BrettAF3D is offline   Reply With Quote
Old 06-06-2008, 02:33 AM   #2
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 2,407
Default

yeah, in the class for the object that is being updated, dispatch an event when a property changes via its getter/setter methods.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote
Old 06-06-2008, 02:50 AM   #3
BrettAF3D
Member
 
Join Date: Jul 2005
Posts: 86
Default

Thanks for your interest ...

ActionScript Code:
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 ?
BrettAF3D is offline   Reply With Quote
Old 06-06-2008, 06:52 AM   #4
amarghosh
unRegistered User
 
amarghosh's Avatar
 
Join Date: Feb 2008
Location: Bangalore
Posts: 817
Default

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
__________________
Blog
amarghosh is offline   Reply With Quote
Old 06-06-2008, 08:10 AM   #5
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

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
pj-co is offline   Reply With Quote
Old 06-07-2008, 08:09 PM   #6
BrettAF3D
Member
 
Join Date: Jul 2005
Posts: 86
Default

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...
BrettAF3D is offline   Reply With Quote
Old 06-08-2008, 04:35 AM   #7
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 2,407
Default

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.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!

Last edited by lordofduct; 06-08-2008 at 04:39 AM..
lordofduct is offline   Reply With Quote
Old 06-08-2008, 04:10 PM   #8
BrettAF3D
Member
 
Join Date: Jul 2005
Posts: 86
Default

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...
BrettAF3D is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:35 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.