Skip to main content
Participating Frequently
December 8, 2015
Question

How to add a catalog songlist to xml music player AS3

  • December 8, 2015
  • 1 reply
  • 922 views

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

  /**/

  }

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 8, 2015

is that code working?  (ie, the trace output is what you expect?)

Participating Frequently
December 8, 2015

Yes that code works, Im trying to add to it

kglad
Community Expert
Community Expert
December 8, 2015

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.