...

View Full Version : Turn off auto start on xml flash player



shanparker
04-02-2008, 12:30 AM
I downloaded a really great and pretty simple xml music player that I'm adding to my site. Everything with it seems to work great except that it auto plays the music!! I know a lot of my visitors like to see and hear what I'm listening to - but I also know that I hate when I go to a site and sound just starts playing without my "permission". So I definitely need to get this fixed so that it does not start playing when the page loads.

Thanks in advance for your help.


volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

loader.load(new URLRequest("/jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
play_btn.addEventListener(MouseEvent.CLICK,playSong);
stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
}

function playSong(e:Event):void
{
sc = currentSound.play(pos);
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
}

//----VOLUME----//
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

sof_mc.addEventListener(MouseEvent.CLICK, playAd);

function playAd(e:Event):void
{
ad_mc.play();
}

stopAllSounds();

_Aerospace_Eng_
04-02-2008, 03:46 AM
You can probably get rid of this line

sc = music.play();
and this line

sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
in the whenLoaded function. Can you give us the url to the mp3 player? I would like to play around with it and I'm sure others may want to put it on their site as well.

shanparker
04-02-2008, 03:52 AM
You can probably get rid of this line

sc = music.play();
and this line

sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
in the whenLoaded function. Can you give us the url to the mp3 player? I would like to play around with it and I'm sure others may want to put it on their site as well.

I actually did try to remove the sc line, and it was giving me issues. So I tried removing the second line like you said, and I'm still getting them. The issue when you remove these lines is that it DOES make the autoplay stop. However when try skipping between songs and stopping and starting the player, etc. The tracks start playing over each other and you can't get them to stop!

Here's the player:
http://schoolofflash.com/2008/03/22/flash-xml-music-player-in-actionscript-3/

_Aerospace_Eng_
04-02-2008, 03:55 AM
What if you changed this line

sc = music.play();
to this

sc = music.stop();
?

shanparker
04-02-2008, 03:58 AM
What if you changed this line

sc = music.play();
to this

sc = music.stop();
?


I tried that too! Then it just sticks on "loading" before it loads the XML list. Grrr! At least I know I wasn't too far off on trying before I asked for help!

shanparker
04-02-2008, 04:11 AM
GOT IT!
How the code was written, the "play" was before it retrieved the song name an artist, so I just moved it down and told it to stop as you suggested. Seems to work now.


volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc = music.stop();
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

loader.load(new URLRequest("/jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
play_btn.addEventListener(MouseEvent.CLICK,playSong);
stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
}

function playSong(e:Event):void
{
sc = currentSound.play(pos);
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
}

//----VOLUME----//
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

algraphix
01-10-2009, 01:40 AM
Ok. So i have this same player and its awesome. But i can't figure out the Auto play which ruins the whole site when i implement it in a page. I have tried eerything i think. Here is the code. Let me know. THanks in advance.

volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var songPlaying:Boolean = false;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);


function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);

title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;

sc = music.play();
sc.addEventListener(Event.SOUND_COMPLETE, pauseSong);

}

loader.load(new URLRequest("jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);

stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
songPlaying = true;
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
songPlaying = true;
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

function playSong(e:Event):void
{
if(songPlaying == false)
{
sc = currentSound.play(pos);
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
songPlaying = true;
play_btn.removeEventListener(MouseEvent.CLICK,playSong);
}
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

//----VOLUME----//
var dragging:Boolean = false;
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
dragging = true;
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
if (dragging)
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
dragging = false;
}
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

sof_mc.addEventListener(MouseEvent.CLICK, playAd);

function playAd(e:Event):void
{
ad_mc.play();
}

gnomeontherun
01-10-2009, 10:11 AM
sc = music.play();

This is the play code, try removing it from the whenLoaded function.

algraphix
01-12-2009, 03:54 AM
Thanks for your reply. So i removed that "sc = music.play();". It's almost just perfect man. Now on the very first song, The "play" button wont work. All the other buttons seem to work just fine. But the play buttons wont work just on the first song. here is the full code. Thanks for your help again.

volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var songPlaying:Boolean = false;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

loader.load(new URLRequest("jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
play_btn.addEventListener(MouseEvent.CLICK,playSong);
stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
songPlaying = true;
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, stopSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
songPlaying = true;
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, stopSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

function playSong(e:Event):void
{
if(songPlaying == false)
{

sc = currentSound.play(pos);
sc.addEventListener(Event.SOUND_COMPLETE, stopSong);
songPlaying = true;
play_btn.removeEventListener(MouseEvent.CLICK,nextSong);
}
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

//----VOLUME----//
var dragging:Boolean = false;
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
dragging = true;
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
if (dragging)
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
dragging = false;
}
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

sof_mc.addEventListener(MouseEvent.CLICK, playAd);

function playAd(e:Event):void
{
ad_mc.play();
}

gnomeontherun
01-12-2009, 10:54 AM
Try this instead for the whenLoaded funciton. I don't know AS3, but I assume its this way. Also please wrap your code in the code tags, its easier for us to read.


function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
music.pause(); // This should pause the music after it is told to play, basically cueing it at the start
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

algraphix
01-15-2009, 03:36 AM
Thanks for your reply. I have been trying everything and Everything messes up the site where it runs the animation none stop. The site works fine when i add sc = music.play();. But it plays automatic. when i remove it completely, it works good but the play button seems to play only a milli second of the mp3. All the rest of the buttons work perfect. Any reason why the Play button only plays a millisecond over and over only on the first song? here is the code below. Again thanks for you help..



volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var songPlaying:Boolean = false;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
// sc = music.play();
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

loader.load(new URLRequest("jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
play_btn.addEventListener(MouseEvent.CLICK,playSong);
stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
songPlaying = true;
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, stopSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
songPlaying = true;
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, stopSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

function playSong(e:Event):void
{
if(songPlaying == false)
{

sc = currentSound.play(pos);
sc.addEventListener(Event.SOUND_COMPLETE, stopSong);
songPlaying = true;
play_btn.removeEventListener(MouseEvent.CLICK,nextSong);
}
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

//----VOLUME----//
var dragging:Boolean = false;
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
dragging = true;
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
if (dragging)
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
dragging = false;
}
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

sof_mc.addEventListener(MouseEvent.CLICK, playAd);

function playAd(e:Event):void
{
ad_mc.play();
}

algraphix
01-15-2009, 03:40 AM
Here is the link to the mp3 player. however it has the auto start which i would love to eliminate. thanks again.

http://schoolofflash.com/files/freebies/as3-jukebox/as3-jukebox.zip

gnomeontherun
01-15-2009, 07:48 AM
Ok please stop putting the same code over and over, and please also wrap it in the [ code] tags. Its just hard to read and pointless to post the same code 3 times.

Does this do it?


function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
sc.stop; // This should pause the music after it is told to play, basically cueing it at the start
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

algraphix
01-15-2009, 03:52 PM
sorry for re-listing the whole code. i am new to AS and don't know how to wrap the code yet. I have added what you told me to try.

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
sc.stop; // This should pause the music after it is told to play, basically cueing it at the start
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

i am getting an error 3553 on line 24 wich is "sc.stop; // This should..." line. The music just plays as soon as i click on the page that the player is installed to. and then, the song starts from beginning, playing over and over, as i surf the sites pages.. thanks for your help and sorry for all the code posting.

Al

gnomeontherun
01-15-2009, 04:30 PM
Did you try what the first poster (aero) gave? I should have asked at first.

To put the code tags around, when you are in the text box typing first click the # button in the top row of icons, and then put all of the code between the two tags which pop up.


function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
}

algraphix
01-15-2009, 11:48 PM
Thanks. I have tried what (aero) has posted in post 6. But that makes my all animation run wildly non stop. This seems to happen with everything except these 2 codes.



function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
// sc = music.play();
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}




{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}


Thanks again for teaching me how to use this system.

gnomeontherun
01-16-2009, 12:29 PM
This is claimed to work.


volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
sc = music.stop();
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

loader.load(new URLRequest("/jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
play_btn.addEventListener(MouseEvent.CLICK,playSong);
stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
}

function playSong(e:Event):void
{
sc = currentSound.play(pos);
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
}

//----VOLUME----//
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

algraphix
01-16-2009, 02:15 PM
Thanks again for replying so fast. I have tried this whole code from above, but it for sure does not work. Nothing happens at all. The titles don't load, and none of the songs play either. Nor do the buttons work at all.. Again thanks for trying to help me out.

Al

algraphix
01-16-2009, 02:21 PM
ah ok i seamed to get the titles and songs to load after removing the "/" from "("/jukebox.xml"));". Not all the buttons work, and everything loads, but that play button for the 1st song only, just plays a millisecond over and over sounding like "gggrrrrrrrrrrrrr" only for the 1st song though. If i hit forward, and then back to the first song, it works just perfect. Just when the page loads with the player, does the "grrrrrr"sound happen on the play button. Thanks.

gnomeontherun
01-16-2009, 03:44 PM
volume_mc.slider_mc.useHandCursor = true;

var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var songPlaying:Boolean = false;

var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);

function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
title_txt.text = songlist[0].title;
artist_txt.text = songlist[0].artist;
}

loader.load(new URLRequest("jukebox.xml"));

next_btn.addEventListener(MouseEvent.CLICK,nextSong);
prev_btn.addEventListener(MouseEvent.CLICK,prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
play_btn.addEventListener(MouseEvent.CLICK,playSong);

stop_btn.addEventListener(MouseEvent.CLICK,stopSong);

function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
songPlaying = true;
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}

var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
songPlaying = true;
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}

function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

function playSong(e:Event):void
{
if(songPlaying == false)
{
sc = currentSound.play(pos);
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
songPlaying = true;
play_btn.removeEventListener(MouseEvent.CLICK,playSong);
}
}

function stopSong(e:Event):void
{
sc.stop();
pos = 0;
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}

//----VOLUME----//
var dragging:Boolean = false;
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function dragIt(e:Event):void
{
dragging = true;
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}

function dropIt(e:Event):void
{
if (dragging)
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
dragging = false;
}
}

function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}

sof_mc.addEventListener(MouseEvent.CLICK, playAd);

function playAd(e:Event):void
{
ad_mc.play();
}

This stops the autostart, but I still think it has some issues. I honestly have never learned AS3, so this is really out of my skill range.

algraphix
01-16-2009, 08:25 PM
thank you so much for helping. I do see that the auto start had been eliminated however the first song play button still has the issue of playing the very 1st millisecond of the 1st song only. If you click on forward and then back to come back to the 1st song, the play button works perfect. Thanks. I will post a new thread maybe someone can figure it out. It is such a cool MP3 player otherwise i would look for another one.

gnomeontherun
01-16-2009, 08:46 PM
I don't have this 1 millisecond playing issue. I don't know what the problem is, what version of Flash do you have? No need to start a new thread either.

algraphix
01-16-2009, 08:52 PM
I am using Flash CS3

so u don't have the millisecond issue haa? Im not sure what the problem is. I mean it works perfect when it is on Auto play. With your latest code its almost working just right. Its just the play button on the very first song only has issues. Hope we can figure it out. It is an awesome player. Thanks.

Al



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum