Alright, so I just learned about custom events, and I’m trying it out, but it’s not working too well.
I start off creating buttons of class test:
package
{
import flash.display.MovieClip;
import flash.events.Event
import flash.events.MouseEvent
//import flash.events.EventDispatcher
//import ChangeEvent
public class test extends MovieClip
{
public var pl:Number
public function test(j:Number) : void
{
addEventListener(MouseEvent.CLICK, dspatcher)
pl = j;
}
public function dspatcher(ev:MouseEvent) : void
{
dispatchEvent(new ChangeEvent(pl))
}
}
}
The code for the ChangeEvent class is
package
{
import flash.events.Event;
public class ChangeEvent extends Event
{
static public var CHANGED:String = "changed";
public var pla : int;
public function ChangeEvent(here:int)
{
super(CHANGED, bubbles, cancelable)
pla = here;
}
}
}
I add an Event Listener with:
addEventListener(ChangeEvent.CHANGED,goTo);
and the code for the goTo function is:
public function goTo(e:ChangeEvent) : void
{
var place = e.pla;
if (this.images[place] != null && !this.images[place].parent)
{
this.images[place].loadImage()
addChild(images[place]);
}
images[plhl].alpha = 0
images[place].alpha = 1
}
The problem is that, when I debug it, I set breakpoints at various points and somehow the event dispatches, but the goTo function is never run. Help?