views:

394

answers:

1

Hi, I'm testing Adobe AIR with flex, and I wanted to play a mp3 via an open file dialog, I did that :

import flash.filesystem.*;
import flash.events.Event;
import flash.media.*;
import mx.core.SoundAsset;

public var loadedFile:File;
public var channel:SoundChannel;
public var song:SoundAsset;


private function loadFile():void {
 loadedFile = new File();
 loadedFile.browseForOpen("Open multimedia File");
 loadedFile.addEventListener(Event.SELECT, fileSelected);
}

private function fileSelected(event:Event):void {
 song = new SoundAsset()
 song.load(URLRequest(loadedFile.url));
 channel = song.play();
}

But when I try to open a file, after the Open file dialog close, I get this error :

TypeError: Error #1034: Type Coercion failed: cannot convert "file:///C:/Users/Kedare/Music/05-Scene%20V%20~%20Prelude.mp3" to flash.net.URLRequest.

I can't find anything related to that on Google or another documentation, all the docs I find is related to play a sound using URL and not Local files :(

Any idea of what can be the problem ? What can I do ?

Thank you !

+2  A: 

Change

song.load(URLRequest(loadedFile.url));

to

song.load(new URLRequest(loadedFile.url));
Cory Petosky
Thanks, that works perfectly ! :)
Kedare
Glad to hear it! Please hit that big checkmark next to my answer to mark it as the solution and close the question. :)
Cory Petosky