Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-28-2003, 10:02 PM   #1
Registered User
Join Date: Jun 2003
Location: Vancouver
Posts: 1
Default Action script for simple music toggle

I just need the actionscript for a simple text button.
It is an on/off switch that will turn off and on the background music.

Thanks :-)
studio604 is offline   Reply With Quote
Old 06-29-2003, 12:41 AM   #2
catbert303's Avatar
Join Date: Nov 2002
Location: uk
Posts: 428


first import you music to flash, then open the library. find the sound you just imported and right click on it, select linkage.

from the linkage dialog box choose export for actionscript and fill in the identifier field. click ok.

now you can add some frame actions to control the sound,

ActionScript Code:
mySound = new Sound(this); mySound.attachSound("the_identifier_you_used"); mySound.start(0, 9999); // to begin have the sound playing, loop it 9999 times // now an event handler for a button (with the instance name  soundToggle_btn) to toggle the sound on and off soundToggle_btn.onPress = function() {     this.count++; // add 1 to a variable this.count     if (this.count % 2) { // this.count is an odd number         mySound.stop(); // assuming the music is playing to begin on the first click stop it     } else { // this.count is even         mySound.start(0, 9999); // reststart it     } };

Finally create the button and give it the instance name soundToggle_btn
catbert303 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 12:22 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.