更新:修改标题以更好地反映我的问题
大家好你们好 :)
我今天的问题围绕着我试图从一个子类发送到另一个子类的 CustomEvent。
我已经使用我的 CustomEvent 类将事件从子类传递到我的主类,但我不确定在子类之间由谁来做。
我的自定义事件类
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");
}
}
子类 INTRO - 调度事件
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);
}
}
子类 NAVIGATION - 我正在侦听事件 需要在 Navigation 类中调用此函数:
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");
}
好的,所以我相信我的问题在于导航类,如何在此处正确添加 addEventListener?我的 introPlayButtonClick 函数中没有任何痕迹。
它是如何在我的 Main 类中使用 PAUSE_MOVIE 事件工作的,我是通过变量名 nv 将 eventListener 附加到 Navigation 类:
nv.addEventListener("onPause", pauseMovie); // Inside of MAIN class
但是由于我在导航类中为 INTRO_CLICKED 事件添加了事件侦听器,所以我认为我需要的只是(this.)添加,但到目前为止我还没有触发该事件。
任何想法,提示,想法?