ActionScript播放音频

| 我只是想制作一个简单的.swf文件,该文件在加载时会播放一段音频。这样可以编译,但是当我将其引入浏览器时,什么也没发生。我只能找到基于Sprite的教程,所以我采取了一种刺痛措施,即您可以像扩展Sprite一样扩展Sound。最终版本将毫无头绪,它被称为Java脚本,可以在事件上播放音频。
   package {
            import flash.media.Sound;
            import flash.net.URLRequest;

            public class typeRight extends Sound {
                    public function HelloWorld( ) {
                    load(new URLRequest(\'./sound.mp3\'));
                    play();
                    }
            }
    }
 我不在Flash中工作,因此请不要提供GUI建议; )     
已邀请:
        而不是子类化Sound类,而是创建一个像这样的文档类,其中包含一个Sound类:
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;

    public class SoundPlayer extends Sprite
    {
        protected var _sound : Sound;
        protected var _channel : SoundChannel;

        public function SoundPlayer()
        {
            _sound = new Sound();
            _sound.addEventListener(Event.COMPLETE, soundLoadCompleteHandler);
            _sound.addEventListener(IOErrorEvent.IO_ERROR, loadError);
            _sound.load(new URLRequest(\"./sound.mp3\"));
        }

        protected function soundLoadCompleteHandler(evt : Event) : void
        {
            // Use the _channel object to control sound properties such as pan and volume.
            _channel = _sound.play();
        }

        protected function loadError(evt : IOErrorEvent) : void
        {
            trace (\"ERROR :: \" + evt);
            // You could try recovering from the error here.
        }

    }
}
    

要回复问题请先登录注册