Problem: A signal instance for every object

120 views
Skip to first unread message

Prashant Patankar

unread,
Jun 29, 2012, 3:41:55 AM6/29/12
to as3-s...@googlegroups.com
While using events, if i had an array of button objects and say they all call the listener function onClick after clicking on them.

I can do this with -

for(var i:int = 0; i < button.length; i++)
{
     button[i].addEventListener(MouseEvent.CLICK, onClick);
}

It is very easy for me to remove all the listeners at once or the listener of the target.

How on the earth, am I supposed to this with signals?
I need signal instance for every object and it will only increase the complexity and length of the project.

Simon Richardson

unread,
Jun 29, 2012, 4:32:23 AM6/29/12
to as3-s...@googlegroups.com
Consider using native signals i.e.


i.e.

var sprite : SignalSprite = new SignalSprite();
sprite.signals.click.add(onClick);

// when done with

sprite.signals.click.remove(onClick);

// or even

sprite.signals.click.removeAll();

Robert Penner

unread,
Jun 29, 2012, 6:07:37 AM6/29/12
to as3-s...@googlegroups.com
Each Signal object provides features that are useful for various situations. If you don't need any Signals features, then the cost of the object may not be worth it. But as Simon says, NativeSignal is a good tool for easily using Signals features with display objects.

Robert

Prashant Patankar

unread,
Jun 29, 2012, 7:09:36 AM6/29/12
to as3-s...@googlegroups.com
That was really helpful. You saved my time. Thanks and cheers!

Neil Manuell

unread,
Jun 29, 2012, 5:34:43 AM6/29/12
to as3-s...@googlegroups.com
I don't think that you have to think of it as an Events OR Signals decision

I weigh up the advantages of both, and use accordingly.

For instance I may use events within a complex view component so that I can make use of bubbling,
but then present the world an api with a Signal that aggregates all the necessary info. 

Then again I would use Events to communicate between totally decoupled actors in a frame-work, but use Signals as a tighter binding
between view and mediator, or data and renderer

cheers
Reply all
Reply to author
Forward
0 new messages