0

每次按下按钮时,我都想加载一个新的 URL(它在一个数组中)。我有以下代码可以做到这一点:

    public function selectRadio(radio:Radio):void {
        var soundR:Sound = new Sound(); 

        if(!playing) {
            soundR.load(new URLRequest(radio.getURL()));
            soundChannel = soundR.play();
            playing = true;
        }
        else{
            soundChannel.stop();
            playing = false;
        }

        trace("You are now listening to " + radio.getTitle());
    }

但它给了我这个错误:“将 flash.net:URLRequest 类型的值隐式强制转换为不相关的类型字符串”

如果我像这样离开它,它会起作用:

soundR.load(radio.getURL());

但如果我这样做,我只能按播放和停止 4 次。第四次之后就没有声音了,好像无法加载网址。

有可能解决这个问题吗?

4

1 回答 1

1

Radio.getURL() should return a string instead of a URLRequest?

Ah nevermind I see you tried avoiding that by removing URLRequest, but you are having problems with only 4 connections.

In all but the simplest cases, your application should pay attention to the sound’s loading progress and watch for errors during loading. For example, if the click sound is fairly large, it might not be completely loaded by the time the user clicks the button that triggers the sound. Trying to play an unloaded sound could cause a run-time error. It’s safer to wait for the sound to load completely before letting users take actions that might start sounds playing.

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d25.html

If you can't wait for the sound to completely load you may need NetStream: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html

于 2013-06-14T17:45:59.790 回答