我的闪光自定义事件不会触发我的、自定义、闪光、事件

2023-09-09 21:42:07 作者:拥你在我怀抱

还有就是我的自定义事件的无痕输出,为什么?

与价值属性自定义事件类:

 包{

    进口对象类型:flash.events.Event;

     公共类自定义事件扩展事件
     {
        公共静态常量ON_CUSTOM_EVENT:字符串=onCustomEvent;
        公共VAR值:数字;

        公共功能自定义事件(类型:字符串,气泡:布尔=假,取消:布尔=假):无效
        {
           超(类型,泡沫,取消);
        }

     }

}
 

测试采用了滑盖刚刚重新调度滑块事件类:

 包{

    导入flash.display使用*。
    进口flash.net *。
    进口flash.events *。
    进口fl.events.SliderEvent;
    进口fl.controls.Slider;

    公共类TestCustomEvent扩展影片剪辑{

      私人VAR CEvent的:自定义事件;

      公共职能TestCustomEvent(){

        的addEventListener(Event.ADDED_TO_STAGE,INIT);

      }

      公共职能的init(五:事件):无效{

        removeEventListener(Event.ADDED_TO_STAGE,INIT);

        this.addEventListener(CustomEvent.ON_CUSTOM_EVENT,OnCustomEvent);
        slider.addEventListener(SliderEvent.CHANGE,OnSliderEventChange);

      }



      公共职能OnCustomEvent(事件:自定义事件):无效{

            跟踪(event.value);
      }


      公共职能OnSliderEventChange(事件:的SliderEvent){

            CEvent的=新的自定义事件(OnCustomEvent);
            cEvent.value = event.value;
            则dispatchEvent(CEvent的);
                    跟踪(你好);

      }

    }
}
 

解决方案

ON_CUSTOM_EVENT:字符串= onCustomEvent

与的

CEvent的=新的自定义事件( OnCustomEvent );

(案例题)

闪光豹来电安卓版下载 闪光豹来电appv3.2 最新版 腾牛安卓网

您不应写入字符串第二次,但使用 CustomEvent.ON_CUSTOM_EVENT

There is no trace output of my custom event why ?

CustomEvent class with value property:

package {

    import flash.events.Event;

     public class CustomEvent extends Event
     {
        public static const ON_CUSTOM_EVENT:String = "onCustomEvent";
        public var value:Number;

        public function CustomEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false):void
        {
           super(type, bubbles, cancelable);
        }

     }

}

Test class with a slider which just re-dispatches the slider event:

package {

    import flash.display.*;
    import flash.net.*;
    import flash.events.*;
    import fl.events.SliderEvent;
    import fl.controls.Slider;

    public class TestCustomEvent extends MovieClip {        

      private var cEvent: CustomEvent;

      public function TestCustomEvent() {   

        addEventListener( Event.ADDED_TO_STAGE, init);  

      }

      public function init( e:Event ):void {

        removeEventListener( Event.ADDED_TO_STAGE, init );

        this.addEventListener(CustomEvent.ON_CUSTOM_EVENT,OnCustomEvent);
        slider.addEventListener(SliderEvent.CHANGE,OnSliderEventChange);

      } 



      public function OnCustomEvent(event:CustomEvent): void {

            trace(event.value);
      }


      public function OnSliderEventChange(event:SliderEvent) {

            cEvent = new CustomEvent("OnCustomEvent");
            cEvent.value = event.value;
            dispatchEvent(cEvent);
                    trace("hello");

      }

    }       
}

解决方案

ON_CUSTOM_EVENT:String = "onCustomEvent"

versus

cEvent = new CustomEvent("OnCustomEvent");

(case problem)

You shouldn't write the string the second time but use CustomEvent.ON_CUSTOM_EVENT