Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Flash CS3 Play/Stop audio button problem

New Here ,
Dec 18, 2013 Dec 18, 2013

I made a play/stop audio button with this youtube tutorial (youtube.com/watch?v=XU6oMEFUFF8) but after the sound is finished I want the play button to show up agian.

Here is the actionscript:

import flash.events.MouseEvent;

play_btn.addEventListener(MouseEvent.CLICK,clickha ndler);
stop_btn.addEventListener(MouseEvent.CLICK,clickha ndler);
function clickhandler(event:MouseEvent):void{
swapChildren(play_btn,stop_btn);
}

what code should I add to my current code?

I also can send you the Fla.

TOPICS
ActionScript
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2013 Dec 18, 2013

It's a good idea to include all the code in your question to get a better response.

Where is the code loading the sound?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2013 Dec 18, 2013

By both buttons - play and stop I made a layer named "music". I removed the HIT keyframe and in the DOWN keyframe I drag a music-file from the library.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2013 Dec 18, 2013

You should consider using the Sound class. Here's a quick overview of it:

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html

You'll be able to add event listeners to the sound to know when it completes so you can execute more code, such as swapping the play and stop button. There is an example in that overview of listening for the SOUND_COMPLETE event (e.g. channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);). It should contain everything you need.

A basic example of what you'll end up with (there's many ways to do it) might look something like this:

// just set up and wait for click

var isPlaying:Boolean = false;

var mySound:Sound = new MySoundInLibrary();

var myChannel:SoundChannel = new SoundChannel();

myChannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);

// buttons

play_btn.addEventListener(MouseEvent.CLICK,clickhandler);

stop_btn.addEventListener(MouseEvent.CLICK,clickhandler);

function clickhandler(event:MouseEvent):void

{

 

          swapChildren(play_btn, stop_btn);

 

          if (isPlaying)

          {

                    isPlaying = false;

                    myChannel.stop();

          }

          else

          {

                    isPlaying = true;

                    myChannel = mySound.play();

          }

}

function onPlaybackComplete(e:Event):void

{

          isPlaying = false;

          swapChildren(play_btn, stop_btn);

}

The basic idea is keeping a flag if the audio is currently playing. If it isn't then assign the sound to a channel and play it while setting the flag (isPlaying) to true. If it's already playing, set the flag to false and stop playing the audio.

The swapChildren is run in the onPlaybackComplete() method so when the audio completes the play button is swapped back in front.

Rather than swapping the children I'd urge you to toggle the .visible property instead. It's easy to run commands in the wrong order and get desynched on depth.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2013 Dec 18, 2013

Thank you so much for your fast and widespread response.

I add the code and try some combinations. But it's only getting worse.

I know nothing about flash, that's why I use the youtube movie. My play/stop button is complete, only the play button must show up again after the sound finishes.

Is it possible for you to add a code to help me in flash? When I see your comment, you must be a professional in flash.

I can send you the Fla.!

You can send me an e-mail to contact me on [Removed personal information], so I can mail you back.

Message was edited by: sinious

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2013 Dec 18, 2013

You shouldn't post personal contact information here, spiders will eat it up so I removed it.

Being you're so new to the product I'll suggest an easier route. Here's a different tutorial that goes over what I essentially just explained, by the same author of your previous video:

http://www.youtube.com/watch?v=QZAnlMaSxCQ

I didn't watch the entire movie but I scrubbed it to read the code and I can see he's using code similar to mine. Give it a try and/or download his source.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2013 Dec 19, 2013

Thank you for the warning to write no personal contact information and for removed it.

I know this tutorial and its better to remake my button. Its not take long so I gonna make it today!

I let you know when I did. And if the button suffice to my objective.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2013 Dec 19, 2013

Thank U so much. I have finally the button that I want. It is a simple button for Flash professionals but for me it was hard.

Thanks again!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2013 Dec 19, 2013
LATEST

Glad you got it working and if you're all set please mark a correct answer so we can filter unanswered questions.

You're welcome and good luck!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines