Copy link to clipboard
Copied
Im trying to make a MP3 player that gets the file from a XML hosted on my webpage. The FLA file has 3 keyframes with code.
I have a list from component panel called list, and a dynamic text field called status_txt
I can excecute the program, but when I click a channel in the list I get this error:
TypeError: Error #2007: Parameter url must be non-null.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at PlayingSoundFromXMLfileWeb_fla::MainTimeline/frame3()[PlayingSoundFromXMLfileWeb_fla.MainTimeline::frame3:12]
Doesnt matter what channel I excecute.
Keyframe1:
stop();
import fl.controls.List;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
list.width=stage.stageWidth;
list.height=600
list.x=(stage.stageWidth - list.width)/2;
list.y=0;
list.rowHeight=50;
var myFormat:TextFormat = new TextFormat();
myFormat.color="0xFFFFFF";
list.setRendererStyle("textFormat",myFormat);
var trackToPlay:String;
var pausePosition:int=0;
var songURL:URLRequest;
var i:uint;
var myXML:XML =new XML();
var XML_URL:String ="http://blogglista.no/something.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void{
myXML = XML(myLoader.data);
var firstSong:String = myXML..Song.songTitle[0];
var firstArtist:String = myXML..Song.songArtist[0];
var firstURL:String= myXML..Song.songURL[0];
songURL = new URLRequest(firstURL);
status_txt.text ="1. " +firstSong + "- "+firstArtist;
for each (var Song:XML in myXML..Song){
i++;
var songTitle:String = Song.songTitle.toString();
var songsongURL:String = Song.songURL.toString();
var songArtist:String=Song.songArtist.toString();
//songURL = Song.songURL.toString();
list.addItem({label: i+"."+songTitle+"-"+songArtist, songString: songsongURL,Artist: songArtist, songNum: i});
}
var myArray = new Array(0,0);
list.selectedIndices= myArray;
gotoAndStop(3);
}
Then the second keyframe has this code:
import flash.net.URLRequest;
songURL = new URLRequest(trackToPlay);
And finally the third keyframe has this code:
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.events.Event;
stop();
var snd:Sound=new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext= new SoundLoaderContext(5000, true);
snd.load(songURL, context);
channel = snd.play(pausePosition);
list.addEventListener(Event.CHANGE, itemClick);
function itemClick(event:Event):void{
channel.stop();
status_txt.text = "Now Playing: " + event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songURL;
//trace(event.target.selectedItem);
trace(event.target.selectedItem.songString);
gotoAndPlay(2);
}
My mission is to import quite a lot of stream URLs.
in your 3rd frame, what's this show:
when that shows null or an empty string, fix your parsing in xmlLoaded in your first frame, or fix your xml to work with your parsing.
Copy link to clipboard
Copied
trackToPlay is needed (to be defined and non-null) in frame 2 and isn't defined until after it's used in snd.load(). fix that.
Copy link to clipboard
Copied
I changed
var trackToPlay:String;
to
var trackToPlay:String="http://cast.loungefm.com.ua/terrace128?1372841071202.mp3";
Still getting the same issues unfortunately
Copy link to clipboard
Copied
i assume that's in frame 1.
if so, does frame 2 play before frame 3? (it doesn't look like it.)
Copy link to clipboard
Copied
Yeah, the changes made are in frame 1,
frame 1 plays first. then frame 3 , then frame 2 if the list is clickd and right back to frame 3
Copy link to clipboard
Copied
if frame 2 doesn't play, then songURL is still null and causing that message.
Copy link to clipboard
Copied
Yeah, makes sense. Okay so I tried changing songURL in the first frame aswell.
var songURL:URLRequest;
var something="http://cast.loungefm.com.ua/terrace128?1372841071202.mp3";
songURL = new URLRequest(something);
Copy link to clipboard
Copied
you probably made songURL local to a function. it needs to be global to the timeline.
if you don't understand how to fix that, or you don't think that's the problem, show your frame 1 code.
Copy link to clipboard
Copied
Its global to the timeline( at least not inside a function)
stop();
import fl.controls.List;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
list.width=stage.stageWidth;
list.height=600
list.x=(stage.stageWidth - list.width)/2;
list.y=0;
list.rowHeight=50;
var myFormat:TextFormat = new TextFormat();
myFormat.color="0xFFFFFF";
list.setRendererStyle("textFormat",myFormat);
var trackToPlay:String;
var pausePosition:int=0;
var songURL:URLRequest;
var something="http://cast.loungefm.com.ua/terrace128?1372841071202.mp3";
songURL = new URLRequest(something);
var i:uint;
var myXML:XML =new XML();
var XML_URL:String ="http://blogglista.no/something.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void{
myXML = XML(myLoader.data);
var firstSong:String = myXML..Song.songTitle[0];
var firstArtist:String = myXML..Song.songArtist[0];
var firstURL:String= myXML..Song.songURL[0];
songURL = new URLRequest(firstURL);
status_txt.text ="1. " +firstSong + "- "+firstArtist;
for each (var Song:XML in myXML..Song){
i++;
var songTitle:String = Song.songTitle.toString();
var songsongURL:String = Song.songURL.toString();
var songArtist:String=Song.songArtist.toString();
//songURL = Song.songURL.toString();
list.addItem({label: i+"."+songTitle+"-"+songArtist, songString: songsongURL,Artist: songArtist, songNum: i});
}
var myArray = new Array(0,0);
list.selectedIndices= myArray;
gotoAndStop(3);
}
Copy link to clipboard
Copied
you didn't mention you changed your code and are now redefining songURL in xmlLoaded. comment that line out and retest.
Copy link to clipboard
Copied
Yeah, sorry about that. I have been doing alot of tries here
So this is what ive done now:
//songURL = new URLRequest(firstURL);
Still the same error.
Copy link to clipboard
Copied
show your code for the first and third frames.
Copy link to clipboard
Copied
frame 1:
stop();
import fl.controls.List;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
list.width=stage.stageWidth;
list.height=600
list.x=(stage.stageWidth - list.width)/2;
list.y=0;
list.rowHeight=50;
var myFormat:TextFormat = new TextFormat();
myFormat.color="0xFFFFFF";
list.setRendererStyle("textFormat",myFormat);
var trackToPlay:String;
var pausePosition:int=0;
var songURL:URLRequest;
var something="http://cast.loungefm.com.ua/terrace128?1372841071202.mp3";
songURL = new URLRequest(something);
var i:uint;
var myXML:XML =new XML();
var XML_URL:String ="http://blogglista.no/something.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void{
myXML = XML(myLoader.data);
var firstSong:String = myXML..Song.songTitle[0];
var firstArtist:String = myXML..Song.songArtist[0];
var firstURL:String= myXML..Song.songURL[0];
//songURL = new URLRequest(firstURL);
status_txt.text ="1. " +firstSong + "- "+firstArtist;
for each (var Song:XML in myXML..Song){
i++;
var songTitle:String = Song.songTitle.toString();
var songsongURL:String = Song.songURL.toString();
var songArtist:String=Song.songArtist.toString();
//songURL = Song.songURL.toString();
list.addItem({label: i+"."+songTitle+"-"+songArtist, songString: songsongURL,Artist: songArtist, songNum: i});
}
var myArray = new Array(0,0);
list.selectedIndices= myArray;
gotoAndStop(3);
}
second:
import flash.net.URLRequest;
songURL = new URLRequest(trackToPlay);
third:
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.events.Event;
stop();
var snd:Sound=new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext= new SoundLoaderContext(5000, true);
snd.load(songURL, context);
channel = snd.play(pausePosition);
list.addEventListener(Event.CHANGE, itemClick);
function itemClick(event:Event):void{
channel.stop();
status_txt.text = "Now Playing: " + event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songURL;
//trace(event.target.selectedItem);
trace(event.target.selectedItem.songString);
gotoAndPlay(2);
}
Copy link to clipboard
Copied
copy and paste the error message and indicate the problematic line number.
Copy link to clipboard
Copied
I can run the code. When I push any of the 5 elements in my list, i get this error:
TypeError: Error #2007: Parameter url must be non-null.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at PlayingSoundFromXMLfileWeb_fla::MainTimeline/frame3()[PlayingSoundFromXMLfileWeb_fla.MainTimeline::frame3:12]
Copy link to clipboard
Copied
what do you mean by "...push any...". are you clicking your list items????
if you are that's a completely different problem.
Copy link to clipboard
Copied
I can excecute the program, but when I click a channel in the list I get tht error. Yeah, that was what I first described. Should maybe have made that clearer, sorry
Copy link to clipboard
Copied
in your 3rd frame, what's this show:
when that shows null or an empty string, fix your parsing in xmlLoaded in your first frame, or fix your xml to work with your parsing.
Copy link to clipboard
Copied
It showed null. You where right as always.
I changed the list addItem in frame 1 to this:
list.addItem({label: i+"."+songTitle, kgladMVP: songsongURL});
and changed the trackToPlay in frame3.
trackToPlay = event.target.selectedItem.kgladMVP;
Thank you very much kglad!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now