Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Turn off auto start on xml flash player

    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.

    Code:
    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();

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can probably get rid of this line
    Code:
    sc = music.play();
    and this line
    Code:
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    You can probably get rid of this line
    Code:
    sc = music.play();
    and this line
    Code:
    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/...ctionscript-3/

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What if you changed this line
    Code:
    sc = music.play();
    to this
    Code:
    sc = music.stop();
    ?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    shanparker (04-02-2008)

  • #5
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    What if you changed this line
    Code:
    sc = music.play();
    to this
    Code:
    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!

  • #6
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

    Code:
    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;
    }

  • #7
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I Need Help with this.

    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();
    }

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Code:
    sc = music.play();
    This is the play code, try removing it from the whenLoaded function.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hey Jeremy

    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();
    }

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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.

    Code:
    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);
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #11
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still haven't got it but real close

    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();
    }

  • #12
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/freeb...s3-jukebox.zip

  • #13
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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?

    Code:
    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);
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #14
    New Coder
    Join Date
    Jan 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still doesn't seem to work

    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

  • #15
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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.

    Code:
    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;
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •