I am trying to create a music player which has a drag and drop options for the playlist. the title has to be dragged onto a target and then this enables the music player to read the specific genre and plays it songs from the XML playlist. I dont seem to get this working. I have pasted the codes below. The music player plays only one playlist and its like after you click play and not by dragging the title. I cant drag the title too. Below are my codes for the FLA file.
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import fl.events.SliderEvent;
import flash.media.SoundTransform;
a.source="media/artist1.jpg"
var startX:Number;
var startY:Number;
var player:MovieClip = this;
var catalog:XML;
var songList:XMLList;
var songsTotal:Number;
var sound:Sound;
var soundChannel:SoundChannel;
var currentSong:Number = 0;
var songPosition:Number;
var songPaused:Boolean;
var XMLLoader:URLLoader = new URLLoader();
XMLLoader.load(new URLRequest("playlist_R&R.xml"));
XMLLoader.load(new URLRequest("playlist_reggae.xml"));
XMLLoader.load(new URLRequest("playlist_hr.xml"));
XMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var anXMLplayList:XML = new XML(e.target.data);
songList = anXMLplayList.song;
trace(songList);
songsTotal = songList.length();
XMLLoader.removeEventListener(Event.COMPLETE, processXML);
XMLLoader = null;
}
init()
///////////////// MC Drag & Drop //////////////////////
function init(){
mc_rocknroll.buttonMode = true;
mc_hr.buttonMode = true;
mc_reggae.buttonMode = true;
mc_rocknroll.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
mc_rocknroll.addEventListener(MouseEvent.MOUSE_UP, dropIt);
mc_hr.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
mc_hr.addEventListener(MouseEvent.MOUSE_UP, dropIt);
mc_reggae.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
mc_reggae.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}
function pickUp (e:MouseEvent){
var thisPiece:MovieClip = MovieClip(e.target);
startX = thisPiece.x;
startY = thisPiece.y;
thisPiece.startDrag(true);
player.setChildIndex(thisPiece, player.numChildren -1);
}
function dropIt (e:MouseEvent){
//trace(square_mc.dropTarget.parent.name);
var thisPiece:MovieClip = MovieClip(e.target);
thisPiece.stopDrag();
if((thisPiece.dropTarget!=null)&&(thisPiece.dropTarget.parent.name == "target" + thisPiece.name)){
thisPiece.x = thisPiece.dropTarget.parent.x;
thisPiece.y = thisPiece.dropTarget.parent.y;
thisPiece.mouseEnabled = false;
thisPiece.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
thisPiece.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
}else{
thisPiece.x = startX;
thisPiece.y = startY;
}
}
function playSong(aSong:Number):void {
// variables for the Title, Artist and associated song in the song list
var aEra = songList[aSong].@era;
var aTitle = songList[aSong].@title;
var anArtist = songList[aSong].@artist;
var aHighest = songList[aSong].@highest;
var aYear = songList[aSong].@year;
var aURL = songList[aSong].@url;
era_txt.text = aEra;
title_txt.text = aTitle;
artist_txt.text = anArtist;
highest_txt.text = aHighest;
year_txt.text = aYear;
if (soundChannel) {
soundChannel.stop();
soundChannel.removeEventListener(Event.SOUND_COMPLETE, onNext);
}
sound = new Sound();
sound.load(new URLRequest(aURL));
soundChannel = sound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE, onNext);
}
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void {
currentSong++;
if (currentSong>=songsTotal) {
currentSong=0;
}
playSong(currentSong);
}
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void {
currentSong--;
if (currentSong<0) {
currentSong = songsTotal-1;
}
playSong(currentSong);
}
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void {
if (soundChannel) {
songPosition = soundChannel.position;
soundChannel.stop();
songPaused=true;
}
}
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void {
if (songPaused) {
soundChannel = sound.play(songPosition);
songPaused=false;
} else if (!soundChannel) {
playSong(currentSong);
}
}
No comments:
Post a Comment