Strike Force Heroes 2
The explosive sequel to the hit game Strike Force Heroes!
3.95 / 5.00 9,858 ViewsObsolescence
Defeat the enormous mechanical beasts--and become one of them.
4.02 / 5.00 45,486 ViewsHi all. Now I did my homework about making Custom events in as3 and to date I haven't been able to get the silly thing to work. I've checked it out and it does indeed dispatch my custom event but my listener never receives it.
here's what going on
My Custom Event:
import flash.events.Event
public class BulletEvent extends Event
{
public static const BULLET_EVENT:String = "bulletEvent";
public var dataObj:String;
public function BulletEvent(type:String, dataObj:String = null)
{
this.dataObj = dataObj;
super(type, false, false);
}
override public function clone():Event
{
return new BulletEvent(type, dataObj);
}
}
my dispatcher dude he does work and he's located in my hero class
if (spaceKey)
{
var data:String = "HeroShot"
dispatchEvent(new BulletEvent(BulletEvent.BULLET_EVENT, data));
}
Now my eventlistener guy. He's the dude that isn't catching my event
package Bullets
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
public class BulletManager extends Sprite
{
public function BulletManager()
{
addEventListener(BulletEvent.BULLET_EVENT, handleBullet);
}
public function handleBullet(event:BulletEvent):void
{
var mydata:String = event.dataObj;
trace("works");
}
}
}
Thanks in advance
You should probably get rid of the dataObj var and instead add more types of BulletEvents. Like BulletEvent.HeroShot or something. Either way, I assume you put a trace after the dispatchEvent function, but try putting one where you add the listener. I do the same stuff with my events, minus the dataObj, and it's fine/
Look no further: http://msghero.newgrounds.com/
Since you attached the listener to the BulletManager, that object must dispatch the event, if any objects inside the object dispatch it that listener will not catch it. If you want nested objects to be caught by that listener you'll need to bubble it.
At 8/1/12 08:39 PM, MintPaw wrote: Since you attached the listener to the BulletManager, that object must dispatch the event, if any objects inside the object dispatch it that listener will not catch it. If you want nested objects to be caught by that listener you'll need to bubble it.
That's probably my issue. I was trying to catch an event outside the class that dispatched it.
thanks; oh and nice sig.