Is it possible to grab an event, hold it in a class property, do some action, then, when that action is complete, dispatch an event and then retrieve the original event.target in the listener?
I am trying to avoid using a custom event for now, as it is giving me massive amounts of heartburn when dispatching it from a loaded SWF.
Here is some code (that doesn't work) that hopefully will help to understand what I am attempting to do:
package
{
import fl.transitions.easing.Regular;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class Document extends MovieClip
{
protected var _event:Event;
public function Document():void
{
initLoader();
}
protected function initLoader():void
{
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest('some_url.xml'));
loader.addEventListener(Event.COMPLETE, intermediaryHandler);
}
protected function intermediaryHandler(event:Event):void
{
_event = event;
doSomeAction();
}
protected function doSomeAction():void
{
var tween:Tween = new Tween(someObject, "alpha", Regular.easeIn, 0, 1, 5);
tween.addEventListener(TweenEvent.MOTION_FINISH, tweenHandler);
}
protected function tweenHandler(event:TweenEvent):void
{
/*
* Imagine some object is listening to this class for Event.COMPLETE.
* I would like to retrieve the event.target that I could have retrieved
* in the `intermediaryHandler()` method, in the listener to the following
* event being dispatched:
*/
dispatchEvent(_event);
}
}
}
I am able to stash the event in a class variable, and then access it later, but the cherry on the icing would be to get it from the event fired withing tweenHandler()
in my example above.
Edit
Well, it doesn't look possible (thanks @bhups for the explanation). I am currently storing the retrieved event in a property _event
and then getting it at a later time when I need it. This seems to work, but isn't wonderful.