dispatchEvent(new MouseEvent(MouseEvent.CLICK))在as3中不起作用

时间:2013-12-13 13:30:55

标签: actionscript-3 movieclip dispatchevent

我试图通过点击它来调用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));
        }


    }
}

我的代码中哪一部分错了?

1 个答案:

答案 0 :(得分:0)

问题是您没有在任何地方MouseEvent.CLICK监听MouseEvent.MOUSE_UP。试着听MouseEvent.CLICK