0

I want to load a new URL (which is in a array), everytime I press the button. I have the following code to do so:

    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());
    }

But it gives me this error: "implicit coercion of a value of type flash.net:URLRequest to an unrelated type string"

It works if I just leave it like this:

soundR.load(radio.getURL());

But if i do so, I can only press play and stop 4 times. After the fourth there is no sound, like it can't load the URL.

Is it possible to fix this?

6
  • 1
    What's happening in radio.getURL()? Commented Jun 14, 2013 at 16:23
  • getURL must return a URLRequest and the constructor for a new URLRequest("string"); expects a String hence the implicit coercion error. In terms of it not working any more are you sure you're testing with a flash debug player are you running in debug mode:adobe.com/devnet/flash/articles/flash_as3_debugging.html if testing in a browser verify debug player is installed helpx.adobe.com/flash-player/kb/find-version-flash-player.html if not get it adobe.com/support/flashplayer/downloads.html Commented Jun 14, 2013 at 17:35
  • Radio is a class like so: public class Radio { private var title:String; private var url:URLRequest; public function Radio(title:String, url:URLRequest) { this.title = title; this.url = url; } public function getTitle():String { return title; } public function getURL():URLRequest { return url; } } In model, where the selectRadio function is, a array is created and the URL is there: private var radio1:Radio = new Radio("P1", new URLRequest("live-icy.gss.dr.dk/A/A03L.mp3")); Commented Jun 14, 2013 at 17:37
  • I'm using the standard debug in flash builder Commented Jun 14, 2013 at 17:40
  • If you use Chrome it uses it's own built in Flash Player instead of one you install, verify at the find version link above that it reports as Debug YES Commented Jun 14, 2013 at 17:51

1 Answer 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

Sign up to request clarification or add additional context in comments.

1 Comment

I found the problem. I needed to close() the stream after I stop the soundChannel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.