Using Custom Events and bubbleing!
Hello,
So heres the issue I'm haveing, my event listener is not being triggered from the parent, and not retrieving my string for each button being clicked on.
Here is the event listener which listens for the subclass to dispatch an event called MenuEvent.LOAD_PAGE and then passes a string to a variable thats called whatPage thats defined within my custom event.
page_mc.addEventListener(MenuEvent.LOAD_PAGE, loadPage, false, 0, true);
private function loadPage(e:MenuEvent):void
{
trace("This page loading is: "+e.whatPage);
}
which my sub class dispatches a event and passes a string of my page being clicked:
var _passPageSelected:String = String(e.target.data);
this.dispatchEvent(new MenuEvent(MenuEvent.LOAD_PAGE, _passPageSelected, true));
Heres my custom event:
package
{
import flash.display.*;
import flash.events.*;
public class MenuEvent extends Event
{
public static const LOAD_PAGE:String = "loadPage";
public var whatPage:String;
// Initialization:
public function MenuEvent($type:String, $id:String, $bubbles:Boolean = false, $cancelable:Boolean = false)
{
this.whatPage = $id;
super($type, $bubbles, $cancelable);
/*trace("Type sent is: "+ $type);
trace("Page selected is: "+ $id);
trace("Bubbles is set to: "+$bubbles);*/
}
public override function clone():Event
{
return new MenuEvent(type, this.whatPage, bubbles, cancelable);
}
public override function toString():String
{
return formatToString("MenuEvent","whatPage","type","bubbles","cancelable");
}
}
}
Hopefully somebody could me out with this issue I'm haveing thanks!.
abe