Skip to main content
Participant
September 5, 2011
Question

Please help play/pause toggle button :( 2days no sleep

  • September 5, 2011
  • 3 replies
  • 2684 views

yes I currently started getting into webdesign and downloaded adobe flash trial as well as dreamweaver trial.

I am very lost on how to add the toggle button. I have tried various codes and watched 2hrs+ youtube tutorials

this is the code I am using.

import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.Event;

var isplaying:Boolean = true;
var lastposition:Number; - 0;

var mysound:music = new music (ASAP.mp3)

var soundchannel:SoundChannel = SoundChannel();

soundchannel = mysound.play(0,0);

soundchannel.addEventListener(Event.SOUND_COMPLETE,
         onPlaybackComplete1);
        
              function onPlaybackComplete1(event:Event):void
            {
             lastposition = 0;
             soundchannel.stop();
             BTNplay.btn_pause.invisible = false;
             trace("finished");
             isPlaying=false;
            
            }
           
            BTNplay.addEventListener(MouseEvent.CLICK, playsound);
            function playsound(event:MouseEvent):void
            {
             if (! isPlaying)
             {
              soundchannel = mysound.play(lastposition,0);
              BTNplay.btn_pause.visible = true;
             
             }
             else
             {
              lastposition = soundchannel.position;
              soundchannel.stop();
              BTNpause.btn_pause .visible = false;
              trace(lastposition.toFixed(0), mysound.lenght.toFixed
              (0));
              isPlaying = false;
             }
            
             soundchannel.addEvenListener(Event.SOUND_COMPLETE,
             onPlaybackComplete);
            
             function onPlaybackComplete(event:event):void
             {
              lastposition = 0;
              soundchannel.stop();
              BTNpause.btn_pause.visible = false;
              trace("finished");
              isPlaying=false
             }
            }
           
I ADDED THIS.

            BTNplay.onRelease = function playsound(event:MouseEvent):void {
ns.pause(false);
BTNplay._visible = false;
BTNpause._visible = true;
};

BTNpause.onRelease = function playsound(event:MouseEvent):void {
ns.pause(true);
BTNplay._visible = true;
BTNpause._visible = false;
};

PLEASE HELP

This topic has been closed for replies.

3 replies

kglad
Community Expert
Community Expert
September 5, 2011

try:


import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.Event;

var isplaying:Boolean = true;
var lastposition:Number; - 0;

var mysound:music = new music (ASAP.mp3)

var soundchannel:SoundChannel = SoundChannel();

soundchannel = mysound.play(0,0);

soundchannel.addEventListener(Event.SOUND_COMPLETE,
         onPlaybackComplete1);
        
              function onPlaybackComplete1(event:Event):void
            {
             lastposition = 0;
             soundchannel.stop();
             BTNplay.btn_pause.invisible = false;
             trace("finished");
             isPlaying=false;
            
            }
           
            BTNplay.addEventListener(MouseEvent.CLICK, playsound);
            function playsound(event:MouseEvent):void
            {
             if (! isPlaying)
             {
              soundchannel = mysound.play(lastposition,0);
              BTNplay.btn_pause.visible = true;
             
             }
             else
             {
              lastposition = soundchannel.position;
              soundchannel.stop();
              BTNpause.btn_pause .visible = false;
              trace(lastposition.toFixed(0), mysound.lenght.toFixed
              (0));
             }

isPlaying=!isPlaying

}            
             soundchannel.addEvenListener(Event.SOUND_COMPLETE, onPlaybackComplete);
            
             function onPlaybackComplete(event:event):void
             {
              lastposition = 0;
              soundchannel.stop();
              BTNpause.btn_pause.visible = false;
              trace("finished");
              isPlaying=false
             }

SkatslotAuthor
Participant
September 5, 2011

thank you for your effort. unfortunately it dosent work

it just plays the sound but the buttons dont toggle etc.

ADOBE provides this code free code in its database

And I have tried to tweak it to make it fit my preferances

but I failed. I got the pause image up but it came up at the top

of the screen

/* Click to Play/Stop Sound
Clicking on the symbol instance plays the specified sound.
Clicking on the symbol instance a second time stops the sound.

Instructions:
1. Replace "http://www.helpexamples.com/flash/sound/song1.mp3" below with the desired URL address of your sound file. Keep the quotation marks ("").
*/

BTNplay.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound_3);

var fl_SC_3:SoundChannel;

//This variable keeps track of whether you want to play or stop the sound
var fl_ToPlay_3:Boolean = true;

function fl_ClickToPlayStopSound_3(evt:MouseEvent):void
{
if(fl_ToPlay_3)
{
  var s:Sound = new Sound(new URLRequest("ASAP.mp3"));
  fl_SC_3 = s.play();
}
else
{
  fl_SC_3.stop();
}
fl_ToPlay_3 = !fl_ToPlay_3;
}

kglad
Community Expert
Community Expert
September 5, 2011

BTNplay will toggle your sound if you use the code i suggested.

Participating Frequently
September 5, 2011

First of all, at least you are trying. Flash is a fabulous tool and a technology which does require some prior knowledge. Some folks try to learn it overnight (nothing is wrong with that approach) and commit themselves to a deliverable which is beyond their current skill sets. I don't think you should burn yourself out by staying up for countless hours, you would most probably end up being exhausted and hating the tool. And if it is a matter of life and death, and you need to deliver this piece at all cost then there are some fabulous folks here on this forum who can extend you their services to get the job done right, and get that ugly moneky off your back.

Thanks.

SkatslotAuthor
Participant
September 5, 2011

Thank you for your words

I have actually made one website. and banners in html

I just now decided to do flash and autoscript. I think its the same concept

And also

I would also appreciate if someone shared

the code to make the mp3 file autoplay.

kglad
Community Expert
Community Expert
September 5, 2011

you added as2 code.  that should have cause quite a few errors.  if it didn't you're not publishing for as3 and should still be seeing errors.

so, are you publishing for as2 or as3?

SkatslotAuthor
Participant
September 5, 2011

I am using adobe autoscript 3.0 on flash cs5.5