Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Senior Member ravensjeff's Avatar
    Join Date
    Aug 2007
    Location
    Maryland
    Posts
    125
    Member #
    15751
    I'm a flash newbie by all accounts...but I have a 30 second radio ad in mp3 format that I want visitors to be able to play when they click on my image. I have followed this tutorial:

    http://www.flash-here.com/tutorials/...lay_sound.html

    I didn't follow step four and the "play button" that they tell you to make in step "three" is a button that says "hear our radio ad" and I changed the Loop from 10 to 1 because I only want it to play once...those are the only changes I've made. The whole thing works great.

    Here is my question:

    The action script in this tutorial starts the sound on release. Problem is that if someone clicks and releases the button multiple times, it will start the clip each time and play it over itself. It works this way in their demo too. You can click it multiple times and hear the jarbled mess you end up with. There must be a way to do this so it only plays once...so who can tell me what to do?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    One way you could do it is create a boolean variable and when they click on the button set the variable to true (meaning the sound clip is playing).

    Your logic will be something like this

    Code:
    var playing = false; /* have this outside of the button click */
    
    /* Then in the on(release) event of the start button have something like the below */
    
    on(release)
       {
          if(playing == false)
          {
              /* start the clip here */
              _root.snd.start(0,1);
              playing = true;
          }
       }
    
    
    /* Then in the on(release) event of the stop button have something like this
    
    on(release)
       {
          if(playing == true)
          {
              _root.snd.stop();
              playing = false;
          }
       }

  4. #3
    Senior Member ravensjeff's Avatar
    Join Date
    Aug 2007
    Location
    Maryland
    Posts
    125
    Member #
    15751
    Thank you. I follow all of that except I am unclear about where I place the initial
    Code:
    var playing = false;

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I am not an expert of ActionScript or Flash, but that line of code needs to be somewhere where both buttons can access it.

    Maybe if the frame has an on(load) event or something similar.

  6. #5
    Senior Member ravensjeff's Avatar
    Join Date
    Aug 2007
    Location
    Maryland
    Posts
    125
    Member #
    15751
    Thank you again for the reply.

    In the frame seems like the natural location and that is where I have placed it. However, it doesn't work for me...the sound does not play. I think I have determined that the problem is not in the location of the variable. If I remove the second on(release) statement, but leave the first dependant on the variable, the sound does play. Perhaps the second on(release) trumps the first and because it is false, it plays nothing.

    If I reverse the two statements, it does solve my problem with the sound clips playing over one another...it just restarts on the second click. Which is good enough for me.

    Thanks again for your help.

  7. #6
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well heres the logic.

    Code:
    set playing to false
    On start button click
      if playing is false
         play sound
         set playing to true
      end if
    end start button click
    
    On stop button click
       if playing is true
         stop sound
         set playing to false
       end if
    end stop button click
    So it should work, because when the start button is first pressed then the sound will play. If it is clicked again a new sound will not start.

    When the stop button is clicked (even if they click it before the stop button) nothing should happen. If the stop button is clicked once the start button has been clicked then the sound will stop.

    So maybe the flash movie is losing the playing variable value.

  8. #7
    Junior Member
    Join Date
    May 2008
    Posts
    24
    Member #
    16855
    You could just import the mp3 into frame 2 and make sure the sound sync is streamed, not event. Then create a play button on frame one and insert a stop action on that frame to make sure the movie doesn't automatically proceed to frame 2. For the play button, actions cript should be:

    on (release) {
    gotoAndPlay(2);
    }

    Starting on frame 2, get rid of the play button.
    On the last frame of the sound, put this:

    gotoAndStop(1);

    to go back to the beginning, where the play button appears again.

    Hope this helps
    2Shea Creative Graphic Design

    Dull pencils make dull drawings


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:46 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com