3 Replies Latest reply on Feb 28, 2010 10:24 AM by kglad

    Buttons with multiple functions

    el pescado Level 1

      Hello,

       

      So, I am building a Flash site with a boombox animation.  I have the below code I am using.  I am using just two frames.  First frame, is where I put the code in the actions layer, boombox is still.  In the second frame, I placed my movie clips on layers (woofers vibrating & tape deck spins).  No code in second frame.  So, if you hit the play, previous or forward button a song goes on and the animation start.  If you press the pause button, animations stop with music.  I have created 2 functions per button.

       

      2 questions:

       

      1 - Is this the best way to do it?  If I press the buttons quickly, sometimes a song gets stuck and I can't stop, forward, etc.  I was wondering if this was the code?

       

      2 - I am tweening in my pages using AS3 - not timeline.  I have a music and video page (each a movieclip).  Is there a way that once I tween in the new movie clip (non-music of vid page) that the music or video can shut off?

       

       

      Thanks,

       

      CODE:

       

       

      stop()

       

      var my_songs:XMLList;

      var my_total:Number;

       

      var my_sound:Sound;

      var my_channel:SoundChannel;

       

      var current_song:Number = 0;

       

      var song_position:Number;

      var song_paused:Boolean;

       

       

      var myXMLLoader:URLLoader = new URLLoader();

      myXMLLoader.load(new URLRequest("playlist.xml"));

      myXMLLoader.addEventListener(Event.COMPLETE, processXML);

       

      function processXML(e:Event):void {

      var myXML:XML = new XML(e.target.data);

       

      my_songs = myXML.SONG;

      my_total = my_songs.length();

       

      //playSong(0);

       

      myXMLLoader.removeEventListener(Event.COMPLETE, processXML);

      myXMLLoader = null;

       

      }

       

      function playSong(mySong:Number):void {

      var myTitle = my_songs[mySong].@TITLE;

      var myArtist = my_songs[mySong].@ARTIST;

      var myURL = my_songs[mySong].@URL;

       

      title_txt.text = myTitle;

      artist_txt.text = myArtist;

       

      if (my_channel) {

      my_channel.stop();

      my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext);

      }

       

      my_sound = new Sound();

      my_sound.load(new URLRequest(myURL));

      my_channel = my_sound.play();

      my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);

      }

       

      //if the next, previous or play button is pushed go to frame 2 where the animation movie clips are placed.

      next_btn.addEventListener(MouseEvent.CLICK, nextdial);

      function nextdial (e:MouseEvent):void{

      gotoAndStop(2);

      }

       

      next_btn.addEventListener(MouseEvent.CLICK, onNext);

      function onNext(e:Event):void {

      current_song++;

      if (current_song>=my_total) {

      current_song=0;

      }

      playSong(current_song);

      }

       

      prev_btn.addEventListener(MouseEvent.CLICK, prevdial);

      function prevdial (e:MouseEvent):void{

      gotoAndStop(2);

      }

       

      prev_btn.addEventListener(MouseEvent.CLICK, onPrev);

      function onPrev(e:MouseEvent):void {

      current_song--;

      if (current_song<0) {

      current_song = my_total-1;

      }

      playSong(current_song);

      }

       

      pause_btn.addEventListener(MouseEvent.CLICK, pausedial);

      function pausedial (e:MouseEvent):void{

      gotoAndStop(1);

      }

       

      pause_btn.addEventListener(MouseEvent.CLICK, onPause);

      function onPause(e:MouseEvent):void {

      if (my_channel) {

      song_position = my_channel.position;

      my_channel.stop();

      song_paused=true;

      }

      }

       

      play_btn.addEventListener(MouseEvent.CLICK, playdial);

      function playdial (e:MouseEvent):void{

      gotoAndStop(2);

      }

       

      play_btn.addEventListener(MouseEvent.CLICK, onPlay);

      function onPlay(e:MouseEvent):void {

      if (song_paused) {

      my_channel = my_sound.play(song_position);

      song_paused=false;

      } else if (!my_channel) {

      playSong(current_song);

      }

      }