-
Loading XML with AS3
I made this MP3 player and I'm trying to load the songs and playlists thru XML files. I keep getting all kinds of errors (#2007, #1006, etc.) and I can't find the problem. Here's the code:
Code:
import fl.events.SliderEvent;
var snd:Sound;
var channel:SoundChannel;
var trans:SoundTransform;
var currSong:String;
var currVol:Number = .5;
var currPan:Number = 0;
var songCount:int = 0;
var songNum:int;
var songTitle;
var songList_XML:XML;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("songList_XML.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
function errorHandler(event:IOErrorEvent):void
{
songTitle.text = "XML loading error: " + event;
}
function xmlLoaded(event:Event):void
{
songList_XML = new XML(xmlLoader.data);
song1.addEventListener(MouseEvent.CLICK, chooseSong);
song2.addEventListener(MouseEvent.CLICK, chooseSong);
song3.addEventListener(MouseEvent.CLICK, chooseSong);
song4.addEventListener(MouseEvent.CLICK, chooseSong);
var setSongs;
var chooseSong;
}
function setSongs():void
{
for(var i = 0; i < 4; i++)
{
var titleText:String = songList_XML.song[i].name;
var artistText:String = songList_XML.song[i].artist;
var clipTitle = this["song" + (i + 1)].title;
var clipArtist = this["song" + (i + 1)].artist;
clipTitle.text = titleText;
clipArtist.text = artistText;
}
}
panSlide.visible = false;
volSlide.visible = false;
volSlide.addEventListener(SliderEvent.CHANGE, volumeChange);
panSlide.addEventListener(SliderEvent.CHANGE, panChange);
function chooseSong(e:MouseEvent):void
{
switch (e.currentTarget.name)
{
case "song1":
songNum = 0;
currSong = songList_XML.song[songNum + songCount].file;
break;
case "song2":
songNum = 1;
currSong = songList_XML.song[songNum + songCount].file;
break;
case "song3":
songNum = 2;
currSong = songList_XML.song[songNum + songCount].file;
break;
case "song4":
songNum = 3;
currSong = songList_XML.song[songNum + songCount].file;
break;
}
if (snd != null)
{
channel.stop();
}
snd = new Sound();
snd.load(new URLRequest(currSong));
channel = new SoundChannel;
trans = new SoundTransform(currVol, currPan);
channel = snd.play();
channel.soundTransform = trans;
panSlide.visible = true;
volSlide.visible = true;
volLabel.text = ">>> " + int(currVol * 100);
panLabel.text = ">>> " + int(currPan * 100);
snd.addEventListener(Event.ID3, id3Handler);
}
function id3Handler(event:Event):void
{
var id3:ID3Info = snd.id3;
if (id3.songName != null)
{
songTitle.text = id3.songName + "\n";
info.text = "Artist: " + id3.artist + " <> Album: " + id3.album;
info.appendText("Album: " + id3.album);
info.appendText("\n" + "Available at: " + "SoundEffects.com");
}
}
var format:TextFormat = new TextFormat();
format.font = "Comic Sans MS";
format.color = 0xFFFF00;
format.size = 10;
format.url = "http://www.soundeffects.com/";
info.defaultTextFormat = format;
function volumeChange(e:SliderEvent):void
{
currVol = e.target.value;
volLabel.text = "Current Volume: " + int(currVol * 100);
trans.volume = currVol;
channel.soundTransform = trans;
}
function panChange(e:SliderEvent):void
{
currPan = e.target.value;
panLabel.text = "Current Pan: " + int(currPan * 100);
trans.pan = e.target.value;
channel.soundTransform = trans;
}
-
XML Code
Here's the XML code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<songlist>
<song>
<file>..MP3s/Air Horn.mp3</file>
<name>Air Horn</name>
<artist>Dozer Boy Miller</artist>
<album>Air Horn Sounds</album>
<youtube>http://www.youtube.com/watch?v=AEPauEupXRc</youtube>
</song>
<song>
<file>..MP3s/Evil Laugh.mp3</file>
<name>Evil Laugh</name>
<artist>Glenn Wright</artist>
<album>Evil Sounds</album>
<youtube>http://www.youtube.com/watch?v=pVY1-v97Mic</youtube>
</song>
<song>
<file>..MP3s/Phone Vibrating.mp3</file>
<name>Phone Vibrating</name>
<artist>Jokikiba</artist>
<album>Everyday Sounds</album>
<youtube>http://www.youtube.com/watch?v=lACDJVKV1no</youtube>
</song>
<song>
<file>..MP3s/Register Cha Ching.mp3</file>
<name>Register Cha Ching</name>
<artist>Jokikiba</artist>
<album>Everyday Sounds</album>
<youtube>http://www.youtube.com/watch?v=Wj_OmtqVLxY</youtube>
</song>
</songlist>
-
Senior Member
Just by looking at the xml, i would guess it has something to do with an incorrect file path.
Code:
<file>..MP3s/Air Horn.mp3</file> // should either be ../MP3s or /../MP3s
Either way you can just put the full path to test and see if it is the path.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|