Update: Modified title to better reflect my question
Hi everybody :)
My question today revolves around a CustomEvent I'm trying to send from one sub Class to another.
I've used my CustomEvent class to pass an event from a sub Class to my main class fine, but I'm not sure who to do that between sub classes.
My Custom Event Class
package src.events {
import flash.events.Event;
public class CustomEvent extends Event
{
public static const CHANGE:String="onChange";
public static const COMPLETE:String="onComplete";
public static const IMAGE_LOADED:String="onImageLoaded";
public static const SWF_LOADED:String="onSWFLoaded";
public static const SWF_UNLOAD:String="onSWFUnload";
public static const CLICK:String="onClick";
public static const PAUSE_MOVIE:String="onPause";
public static const INTRO_CLICKED:String="introClicked";
public var params:Object;
public function CustomEvent(type:String, params:Object, bubbles:Boolean = false, cancelable:Boolean = false)
{
super(type, bubbles, cancelable);
this.params=params;
}
public override function clone():Event
{
return new CustomEvent(type, this.params, bubbles, cancelable);
}
public override function toString():String
{
return formatToString("CustomEvent","params","type","bubbles","cancelable");
}
}
Sub Class INTRO - dispatches event
package src.display {
import gs.easing.*;
import gs.TweenLite;
import flash.text.*;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
// ☼ ----------------------------------------- Imported Custom Classes
import src.events.CustomEvent;
// ☼ ----------------------------------------- Intro Class
public class Intro extends Sprite
{
private var playBtn:MovieClip;
// ☼ ----------------------------------------- Constructor
public function Intro():void
{
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
// ☼ ----------------------------------------- Init
public function init(event:Event):void
{
draw();
}
public function draw():void
{
playBtn = new PlayThumb;
playBtn.buttonMode = true;
playBtn.x = 582;
playBtn.y = 259;
playBtn.alpha = 1;
addChild(playBtn);
playBtn.addEventListener(MouseEvent.MOUSE_UP, clicked);
}
private function clicked(e:MouseEvent):void
{
trace("clicked big play");
dispatchEvent (new CustomEvent(CustomEvent.INTRO_CLICKED, {}));
trace("event = "+CustomEvent.INTRO_CLICKED);
}
}
Sub Class NAVIGATION - where I'm listening for the event Need to call this function inside of the Navigation class:
function introPlayButtonClick(e:CustomEvent):void
{
trace("introPlayButtonClick called");
TweenLite.to(buttons[0], 1, {y:20, ease:Strong.easeOut});
TweenLite.to(buttons[1], 1, {y:navBtnY, ease:Strong.easeOut});
TweenLite.to(introTab, 1, {y:60, ease:Strong.easeOut});
TweenLite.to(scrollerMov, 1, {y:60, ease:Strong.easeOut});
$btn1 = true;
$btn2 = false;
trace("introPlayButtonClick called --- end");
}
Ok so I believe my problem lies in the Navigation Class, how do I correctly add the addEventListener here? I'm not getting any of the traces in my introPlayButtonClick function.
How it worked in my Main class with the PAUSE_MOVIE event, was I attached the eventListener to the Navigation class via the variable name nv:
nv.addEventListener("onPause", pauseMovie); // Inside of MAIN class
But since I'm adding the event listener inside of the Navigation class for the INTRO_CLICKED event I thought all I needed was (this.) added, but so far I'm not getting that event to trigger.
Any ideas, tips, thoughts?