Jump to content


Event passed as parameter to TweenMax.delayedCall becomes 0?

Recommended Posts

I'm sure there's an error in my code, but when I do this ($event is a mouseEvent)


when I get to showDetailScreen($event:MouseEvent)

private function showDetailScreen($event:MouseEvent):void {

$event.current is no longer the button on which I originally clicked, but instead Stage, the trace is:


$event.currentTarget = [object Stage]


and $event itself traces as "0".

trace("$event = " + $event);
TweenMax.delayedCall(0,function ($x:MouseEvent) {trace("delayed call? " + x)},[$event]);


$event = [MouseEvent type="click" bubbles=true cancelable=false eventPhase=2 localX=49.72636795043945 localY=109.43730163574219 stageX=487.6 stageY=709.2 relatedObject=null ctrlKey=false altKey=false shiftKey=false buttonDown=false delta=0]
delayed call? 0
Link to comment
Share on other sites

In the first blurb of code, the $event.currentTarget is the stage because of the way bubbling works (Google it - that may take a little while to wrap your head around how bubbling works). At the time you got the event in your function to begin with, currentTarget was one thing, but then it changes as it goes up the chain, and you're using it in a delayedCall(), so by the time that runs, the currentTarget changed. One simple solution is to just use that in your params:

TweenMax.delayedCall(_gameClickDelay, showDetailScreen, [$event.currentTarget]);

And the second problem you ran into is that you referenced "x" in your trace instead of "$x" which is the parameter you were looking for in your function :) Just a typo. 

Link to comment
Share on other sites

Thanks — first, the second point, my typo, I can only say: doh!, and feel ashamed.


I thought I understood how bubbling works (having pored through Moock several times years ago) — events go from top to bottom in the display hierarchy and then back from bottom to top, and you can watch for them in one direction (I don't remember which) or both —


At this remove I confess I've gotten a little fuzzy.  


I'd always thought that 'currentTarget' is the one that was bound through the addEventListener — that is, if you did abc.addEventListener(Event.WHATEVER,functionario) the currentTarget of functionario would always be abc -- and that 'target' would vary depending on whether you were catching it at some phase in the bubbling, and all of this is dependent on the display hierarchy.  Do I have this backwards?  


But in any case, does the event itself change over time? I think that's what you're saying. That is, with bubbling, if I save an event, and test target (or currentTarget), the bubbling mechanism will actually change it in the event I've saved?  


In the end I had done exactly what you suggested, just grabbed the currentTarget -- worked fine, but I felt rather uneasy as I didn't know why this was happening — your explanation helped, so thatnks!; I hadn't thought of bubbling!  Although I'm apparently unclear about the details, as per above…

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.