Reputation: 1677
I hava scene class that should receive an event when an item is picked up but the event is not fired or will not received.
public class Szene extends MovieClip {
private var items : Array;
public function Szene() {
this.addEventListener(ItemEvent.PICKED_UP, removeItem);
}
public function removeItem(index : int)
{
trace("remove");
this.removeChild(items[index]);
}
...
}
public class FigurControl extends MovieClip {
public function update(event : Event)
{
for(var j=0; j < items.length; j++)
{
if(this.hitTestObject(items[j]))
{
trace("dispatch");
this.dispatchEvent(newItemEvent(ItemEvent.PICKED_UP,j));
}
}
...
public class ItemEvent extends Event {
public static const PICKED_UP : String = "pickedUp";
public var data : int;
public function ItemEvent(type : String, data : int, bubbles : Boolean=false, cancelable : Boolean=false)
{
super(type,bubbles,cancelable);
this.data = data;
}
override public function clone() : Event
{
return new ItemEvent(type,data,bubbles,cancelable);
}
}
}
I get the output "dispatch" but is never received in the method "removeItem" :( whats the reason???
Upvotes: 0
Views: 199
Reputation: 14276
In the constructor, you have:
this.addEventListener(ItemEvent.PICKED_UP, removeItem);
You have the Szene
object listening to itself--it should be listening to the appropriate FigurControl
object instead:
myFigurControl.addEventListener(ItemEvent.PICKED_UP, removeItem);
Upvotes: 1