【问题标题】:dispatchEvent(new MouseEvent(MouseEvent.CLICK)) do not work in as3dispatchEvent(new MouseEvent(MouseEvent.CLICK)) 在 as3 中不起作用
【发布时间】:2013-12-13 13:30:55
【问题描述】:

我试图调用 MovieClip 的鼠标事件,而不是通过单击它。我写了recButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));,但它在这里不起作用是代码的一部分:

   package 
{
    import flash.display.Sprite;
    import flash.media.Microphone;
    import flash.system.Security;
    import org.bytearray.micrecorder.*;
    import org.bytearray.micrecorder.events.RecordingEvent;
    import org.bytearray.micrecorder.encoder.WaveEncoder;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.events.ActivityEvent;
    import fl.transitions.Tween;
    import fl.transitions.easing.Strong;
    import flash.net.FileReference;

    public class Main extends Sprite
    {
        private var mic:Microphone;
        private var waveEncoder:WaveEncoder = new WaveEncoder();
        private var recorder:MicRecorder = new MicRecorder(waveEncoder);
        private var recBar:RecBar = new RecBar();
        private var tween:Tween;
        private var fileReference:FileReference = new FileReference();
        public function Main():void
        {
            recButton.stop();
            activity.stop();
        trace(recButton);
            mic = Microphone.getMicrophone();
            mic.setSilenceLevel(0);
            //mic.activityLevel = 50;
            mic.gain = 100;
            mic.setLoopBack(true);
            mic.setUseEchoSuppression(true);
            Security.showSettings("2");

            addListeners();

        }


        private function addListeners():void
        {
            recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);
            recorder.addEventListener(RecordingEvent.RECORDING, recording);
            recorder.addEventListener(Event.COMPLETE, recordComplete);
            activity.addEventListener(Event.ENTER_FRAME, updateMeter);
        }

        private function startRecording(e:MouseEvent = null):void
        {
            trace("GERE");
            if (mic != null)
            {
                recorder.record();
                e.target.gotoAndStop(2);

                recButton.removeEventListener(MouseEvent.MOUSE_UP, startRecording);
                recButton.addEventListener(MouseEvent.MOUSE_UP, stopRecording);

                addChild(recBar);

                tween = new Tween(recBar,"y",Strong.easeOut, -  recBar.height,0,1,true);
            }
        }

        private function updateMeter(e:Event):void
        {
            activity.gotoAndPlay(100 - mic.activityLevel);

            if(mic.activityLevel > 10 )
                recButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
        }


    }
}

我的代码哪一部分有问题?

【问题讨论】:

    标签: actionscript-3 movieclip dispatchevent


    【解决方案1】:

    问题是你没有在任何地方收听MouseEvent.CLICK,只收听MouseEvent.MOUSE_UP。尝试收听MouseEvent.CLICK

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2014-07-09
      • 2014-12-10
      • 1970-01-01
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多