(feel free to shoot me if this is a bad idea)
Cheat.
Assuming EventDispatcher is a custom class and you're using AS3, create a
method within EventDispatcher to add Singleton as an event listener to
CustomSprite. Something like
public function myAddCustomSpriteListener(eventName:String,
listener:Function):void
{
CustomSprite.addEventListener(eventName, listener) ;
}
And just call the method within Singleton like so:
EventDispatcher.myAddCustomSpriteListener("myEventName", listenerFunction) ;
Jer
On Wed, Mar 17, 2010 at 1:39 PM, Mendelsohn, Michael <
[email protected]> wrote:
> Hi Jason, thanks for responding!
>
> > Make sense?
> Almost. :-)
>
> > What do you mean "The EventDispatcher contains an instance of a sprite."
>
> The EventDispatcher has a private var that's a reference to a custom class
> that extends Sprite.
> The Event Dispatcher is instanced in the singleton, it's not on the stage,
> it just directs traffic, so to speak.
>
> > Normally what you would do is not create an instance of EventDispatcher,
> but instead have your custom class extend Sprite (which already extends
> EventDispatcher anyway), have that sprite dispatch a custom event.
>
> Yes, that's happening.
>
> > Then have your class listen to the instance of that class for the custom
> event you dispatch.
>
> Yes, I'm doing that too.
>
> > So in summary, you write an event class, dispatch
> that custom event from the "sprite" class (the custom class that extends
> sprite) and listen for that event on that instance in your Singleton
> (the fact that it's a Singleton should be irrelevant).
>
> This is the part I'm not getting to work. What I have working is the
> following:
>
> Singleton
> - has private var EventDispatcher
>
> EventDispatcher
> - has private var CustomSprite
>
> CustomSprite dispatches CustomEvent.
>
> EventDispatcher catches CustomEvent from Sprite.
> EventDispatcher dispatches same CustomEvent. <-- unnecessary step??
> Singleton catches CustomEvent from EventDispatcher (passed along from
> CustomSprite).
>
> What I want is:
> CustomSprite dispatches CustomEvent
> Singleton catches CustomEvent.
>
> Within singleton, this does *not* work:
> myEventDispatcher[myCustomSprite].addEventListener...
>
> I have to "pass" the event up the ladder to the singleton. I'd rather leap
> over the EventDispatcher.
>
> - Michael M.
>
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders