You could do something like this without getting into specifics
// main
var model : Model = new Model();
var view1 : ViewClass1 = ViewClass1.createInstance();
var view2 : ViewClass2 = ViewClass2.createInstance();
model.addEventListener( 'ALL', view1 );
model.addEventListener( 'ALL', view2 );
model.position = 10;
// model
import com.qdc.events.QDispatcher;
import com.dynamicflash.utils.Delegate;
class .Model
{
private var _position : Number
// methods
public function dispatchEvent() {};
public function addEventListener() {};
public function Model()
{
QDispatcher.initialize( this );
}
public function set postion( pos : Number ) : Void
{
_postion = pos
dispatchEvent( { type : 'updatePosition', position : pos } )
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike
Anderson
Sent: Thursday, 13 April 2006 2:45 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Using EventDispatcher to update Controls and
otherVariables?
Hello There!
As long as we are on the topic of EventDispatcher, I have another
question that could really help me out.
If I have multiple Controls (and variables) throughout my application,
that were all tied to a SINGLE variable (that changes several times per
second), could I use an EventDispatcher method - to dispatch an event
whenever this specific variable changes, and have ALL those controls
subscribed to that Event, update themselves with this new value?
Right now, I have a Mouse position function (which runs every time the
mouse moves), that updates a TON of TextFields scattered throughout my
application with the mouse coordinates. In my function, I have to go
through Each and Every TextField instance, and update the .text
properties.
Is there a better way to accomplish this, like using the Event system?
Or is this considered such a simple process, that manually setting the
.text properties for a ton of controls is just the easiest way, rather
than dispatching events? (keep in mind, this variable gets updated many
times per second)
This topic has been on my mind for a LONG time now - and I would love a
definitive answer on how to do this.
Thanks in advance!
Mike
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com