Copy link to clipboard
Copied
I am new to actionscript 3.0 and working on an xml driven music player. I have a playlist already but I want to incorporate a catalog list to the player. I want to be able to add songs from the catalog list to the xml playlist which will automatically add the songs to the xml database. Ive search all over for tutorials that I might can learn from but no luck. If there’s anybody out there than can give me some insight I would gratefully appreciate the help thank you. here is the xml code I’m working with.
public class MusicPlayer extends MovieClip {
private var _xmlmp3:XML;//holder all document from xml
private var _index_song:Number = 0;//This will be index for the xml document
private var _sound:Sound;//we need it to stream the sound mp3
private var _sound_position:Number = 0;//we always must know the sound position
private var _soundchannel:SoundChannel;//we need also for streaming(volume, pause, play ....)
private function get _url_mp3_current():String{return this._xmlmp3.song[this._index_song].@url;}//song current url
private function get _artist():String{return this._xmlmp3.song[this._index_song].@artist;}//song artist
private function get _songName():String{return this._xmlmp3.song[this._index_song].@songName;}//song artist
private var _sound_volume:Number = 0.5;
private var _sound_volume_last:Number = 0.5;
private var _sound_panning:Number = 0;
private var _shuffle:Boolean = false;
//private var bytes:ByteArray = new ByteArray();
//private var Sprite:Sprite = new Sprite();
//this.stage.addChild(Sprite);
public function MusicPlayer() {
//adding event when the flash content is added to stage first frame
this.addEventListener(Event.ADDED_TO_STAGE, ADDED_TO_STAGE);
}
//adding event when the flash content is added to stage first frame
//function
private function ADDED_TO_STAGE(e:Event)
{
//init loading xml file for the songs
this.load_xml_file_for_the_songs();
}
private function load_xml_file_for_the_songs()
{
trace("load_xml_file_for_the_songs");
/*
we need url loader for loading the xml file
*/
var xml_loader:URLLoader
=
new URLLoader( );//we create new object instacence of URLLoader
xml_loader.addEventListener(Event.COMPLETE, xml_loader_COMPLETE_LOADING);//we add the event
xml_loader.load(
new URLRequest("PlayList.xml")//this object is urlrequest
);//after that we load the file
//myList.rowHeight = 22;
var textStyle:TextFormat = new TextFormat();
textStyle.size = 12;
textStyle.font = "Arial";
textStyle.color = "0XFFCC00";
myList.setRendererStyle("textFormat", textStyle);
}
//this is event after loading the file
//it is holding the data for the xml player list
private function xml_loader_COMPLETE_LOADING(e:Event)
{
//trace(e.target.data);//just testing
this._xmlmp3 = new XML( e.target.data );//we create xml for flash from text source xml e.target.data
trace( this._xmlmp3 );//just testing
trace( this._xmlmp3.song[0].@url );
//for loop for listing all song items from XML
for(var iitemxml=0;iitemxml<this._xmlmp3.song.length();iitemxml++)
{
trace( this._xmlmp3.song[iitemxml].@songName );
myList.addItem(
{
data:this._xmlmp3.song[iitemxml],//with this object item of the select box will hold xml item for the song
label:this._xmlmp3.song[iitemxml].@songName//with this item we add label for each item of the list
});//ading item to combox box named "myList"
}
this.add_events_to_the_controls();//we are adding to the controls
/**/
}
Copy link to clipboard
Copied
is that code working? (ie, the trace output is what you expect?)
Copy link to clipboard
Copied
Yes that code works, Im trying to add to it
Copy link to clipboard
Copied
other than saying you want to add a 'catalog' list can you explain what you want to add that's not already present?
actually, showing a snippet from your current xml and then showing how you want to change that, might be sufficient.
Copy link to clipboard
Copied
This is how I can explain what Im trying to do. I want 2 separate lists, a catalog of songs and a playlist. the catalog list will hold all songs and the playlist will just have the songs which has been added to the playlist from the catalog. The code I have only displays the playlist. Thank you for the response much appreciated.
Copy link to clipboard
Copied
have you created the catalog xml?
Copy link to clipboard
Copied
yes I tried but wasn't able to populate both list.
Copy link to clipboard
Copied
show your catalog.xml file
Copy link to clipboard
Copied
here's a copy of xml file
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<song url="PlayList/Triumph.mp3" songName="Triumph" artist="WuTang Clan" />
<song url="PlayList/Born To Roll.mp3" songName="Born To Roll" artist="Master Ace" />
<song url="PlayList/Stop Look Listen.mp3" songName="Stop Look Listen" artist="Mc Lyte"/>
<song url="PlayList/Times Up.mp3" songName="Times Up" artist="OC" />
<song url="PlayList/Step Into A World.mp3" songName="Step Into A World" artist="KRS1" />
<song url="PlayList/Lauren Hill - The Miseducation of Lauryn Hill - 02 Lost Ones" songName="Lauren Hill - The Miseducation of Lauryn Hill - 02 Lost Ones" artist="Lauren Hill" />
<song url="PlayList/Hold It Now Hit It.mp3" songName="Hold It Now Hit It" artist="Beasty Boys" />
<song url="PlayList/Throw Them Bows.mp3" songName="Throw Them Bows" artist="Ludacris"/>
<song url="PlayList/Planet Rock.mp3" songName="Planet Rock" artist="The Soul Sonic Force" />
<song url="PlayList/Jam On It.mp3" songName="Jam On It" artist="Newcleus" />
</catalog>
Copy link to clipboard
Copied
that's catalog.xml?
if so, what's the problem with that or how do you want to change that?
Copy link to clipboard
Copied
This is what Im trying to do. lets say I have a catalog of 50 songs. (catalog List) now I want to create a playlist for just 10 songs (playlist). Now I want to be able to add new songs from catalog list to playlist and be able to delete songs from the playlist. I also want to be able to add new songs to the catalog list, which will automatically add the songs to the xml database without rewriting the xml playlist. and Thanks again for your time and response.
Copy link to clipboard
Copied
after parsing catalog.xml in xml_loader_COMPLETE_LOADING(), create an array or new xml for your playlist.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now