Reputation: 3706
Originally I had two functions, the first function being dataLoaded
which had an eventListener in it that spawned a new function called itemClicked
. But if I wanted to add a delayedFunction
and have itemClicked
as an intermittent stage between dataLoaded
and delayedFunction
, how can I access the event.target
or event.currentTarget
of the original listener when I come to reference it in my delayedFunction
?
private function dataLoaded(event:Event):void {
//items properties call - add other calls to master properties later on
items = data.item;
// parsing of each ingredient
for (var i = 0; i < items.length(); i++) {
// instantiation of mcItem (the stage for each item)
_item = new Item();
// sets //over// layer to invisible / transparent
_item.item_btn_over.alpha = 0;
// creates the var itemTextField
_itemTextField = new TextField();
_itemTextField.text = items[i].toString();
// adds textfield to displaylist
_item.addChild(_itemTextField);
//adds items to container displaylist
_container.addChild(_item);
}
_item.parent.addEventListener( MouseEvent.CLICK, itemClicked );
}
function itemClicked(event:MouseEvent):void {
if (event.target is Item) {
var item:Item = Item(event.target);
TweenLite.to(item.btn_delete, 1,{rotation:180});
setTimeout(delayedFunction,5000);
item.parent.removeChild(item);
parseXML(data);
}
}
function delayedFunction():void {
var item:Item = Item(event.target);
item.parent.removeChild(item);
}
(I've mocked up the functions above, so I may be missing some closing parenthesis, but this doesn't matter in relation to my question)
This question has been on my mind for days and I can't think of a way of making the event.target
of the parent _item
accessible to functions other than the listening function.
Upvotes: 0
Views: 343
Reputation: 10510
You can pass arguments to your setTimeout
call like this:
setTimeout(delayedFunction, 5000, event.currentTarget);
Then get the argument from the arguments
array from your delayedFunction
method:
function delayedFunction():void {
var item:Item = arguments[0] as Item;
item.parent.removeChild(item);
}
Have a look at the setTimeout docs if you need information.
Upvotes: 2