Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 动作脚本3:Event.SOUND#u COMPLETE不';t火_Actionscript 3_Audio Player - Fatal编程技术网

Actionscript 3 动作脚本3:Event.SOUND#u COMPLETE不';t火

Actionscript 3 动作脚本3:Event.SOUND#u COMPLETE不';t火,actionscript-3,audio-player,Actionscript 3,Audio Player,好的,我正在为我正在制作的网站制作简单的actionscript-3声音播放器。。。 在这样做的时候,我突然想到声音完成事件由于某种原因没有触发。因此,如果有人注意到我代码中的问题,请回复 package { import flash.events.*; import flash.media.*; import flash.external.*; import flash.net.*; import flash.utils.*; public c

好的,我正在为我正在制作的网站制作简单的actionscript-3声音播放器。。。 在这样做的时候,我突然想到声音完成事件由于某种原因没有触发。因此,如果有人注意到我代码中的问题,请回复

package {
    import flash.events.*;
    import flash.media.*;
    import flash.external.*;
    import flash.net.*;
    import flash.utils.*;

    public class player{

        private var soundChannel:SoundChannel;
        private var sound:Sound;
        private var lastPosition:Number = 0;

        public function player():void{
            ExternalInterface.addCallback("load", this.load);
            ExternalInterface.addCallback("play", this.play);
            ExternalInterface.addCallback("stop", this.stop);
            ExternalInterface.addCallback("reset", this.reset);
        }
        /*
        javascript from inside actionscript:

            ExternalInterface.call("console.log","ipsum");
        */
        private function load(url:String):void{
            var audio:URLRequest = new URLRequest(url);
            try {
                this.soundChannel.stop();
            } catch(e:Error) {
            };
            this.sound = new Sound();
            this.sound.load(audio);
            this.lastPosition = 0;
        }
        private function play():void{
            this.soundChannel = this.sound.play(this.lastPosition);
            this.soundChannel.addEventListener(Event.SOUND_COMPLETE,finished);
            ExternalInterface.call("console.log","started playing");
        }
        private function finished():void{
            this.lastPosition=0;
            this.soundChannel=this.sound.play()
            ExternalInterface.call("console.log","finished playing");
        }
        private function reset():void{
            this.lastPosition = 0;
            this.soundChannel.stop();
        }
        private function stop():void{
            try {
                this.lastPosition = this.soundChannel.position;
                this.soundChannel.stop();
            } catch(e:Error) {
            };
        }

    }
}//package

我认为问题在于
finished()
不接受事件,它应该是:

    private function finished(e:Event):void{
        this.lastPosition=0;
        this.soundChannel=this.sound.play()
        ExternalInterface.call("console.log","finished playing");
    }

在这种情况下,这不适用于我,因为每次我使用play函数时,它都会再次添加EventListener。谢谢你的回复!我认为您应该在load中调用本地stop函数,并且我认为您的finished()函数中出现了运行时错误,因为它无法接受将要传递的事件。运行时错误正在阻止代码的resto运行。我只能假设您没有看到它,因为您已禁用调试或未在调试播放机中运行它。声音是否从未发出?或者只是偶尔?