Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Code for single button Sound Loop (on and off)

Posted on 2005-05-17
12
Medium Priority
?
142 Views
Last Modified: 2010-04-03
Could you help me with a sound clip in Flash MX2004? I currently have two buttons that the viewer can click- one to begin the music after the site is loaded, and one to end the music (the viewer can click either button repeatedly). Could you help me with code so that: 1) the music begins when the site is loaded, and 2) make just one button, so that when the viewer clicks the button (that would say ‘mute’) the music stops, and then the text on the button would be replaced to read ‘music’. When they click the button again (‘music’) the sound begins again, and the button text would be replaced to read 'mute' again.

The code I’m currently using for the two separate buttons, is:

To Start the Sound on button one:
on (release) {
      _root.sound1 = new Sound();
      _root.sound1.attachSound("loop_11");
      _root.sound1.start(0,99)
}

To Stop the Sound on button two:
on (release) {
      _root.sound1.stop()
}
0
Comment
Question by:ccllww
  • 6
  • 6
12 Comments
 
LVL 18

Expert Comment

by:Billystyx
ID: 14020578
put this code on first frame of swf:

_root.sound1 = new Sound();
     _root.sound1.attachSound("loop_11");
     _root.sound1.start();

and make your button a movieclip, with 3 frames:
framelabel1 would be 'stop', framelabel2 would be 'over' and framelabel3 would be 'press'
put a stop();
on each frame,
(make the frames so they mimic your original button),
and make the text on the button's frames dynamic, with a variable name, 'myText'

Then, on _parent level (probably the root), put this code, after naming your mc button instance 'mcbutton'
sound=false;
mcbutton.myText="play";
mcbutton.onRollOver=function(){
this.gotoAndStop("over");
}
mcbutton.onRollOut=function(){
this.gotoAndStop("stop");
}
mcbutton.onRelease=function(){
sound=!sound;
if(sound==false){
this.myText="play";
 _root.sound1.start();
}else{
this.myText="music";
_root.sound1.stop();
}
}

billystyx
0
 

Author Comment

by:ccllww
ID: 14030068
Thanks for you response. I'm still a novice at this... could you help me understand the _parent level? Exactly where do I place this code?
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 14030633
_parent is the level directly above the movieclip you have the code in.
If everything is on the maintimeline, then root will work just as well,
so if the mcbutton is on the maintimeline (dragged onto it from the library) then put the code all on the first frame of the main timeline, so long as your button is there too, and has an instance name
billystyx
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Billystyx
ID: 14044214
If you have a place to upload to you can post the link and I will add the code and comment it, so you can better understand:)

billystyx
0
 

Author Comment

by:ccllww
ID: 14045733
thanks. I'll try it later this afternoon or evening. If I can't get it to work I'll upload to my server so you can help.
0
 

Author Comment

by:ccllww
ID: 14069029
I tried your instructions, and I'm still not able to get it to work. I don't have a separate ftp account to upload to, so that I could post the link. Can I send it directly to your email? The fla file is size 1,172 KB.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 14069088
Yes, its in my profile:)

billystyx
0
 

Author Comment

by:ccllww
ID: 14069348
thank you. I just sent the eamail.
0
 
LVL 18

Accepted Solution

by:
Billystyx earned 2000 total points
ID: 14070321
I changed it slightly to allow you to pause rather than stop and go back to the start - don't know if this is what you wanted.

mcbutton.onRelease=function(){
sound=!sound;
if(sound==false){
this.myText="play";
 _root.sound1.start(num);//this parameter allows you to pause and go on where you left off. Iff
 //you want it to start from scratch just leave it as .start();
}else{
this.myText="music";
num=sound1.position/1000;//the above param uses this calculation for it to work

_root.sound1.stop();
}
}

billystyx
0
 

Author Comment

by:ccllww
ID: 14071201
thank you. I'll give it a try.
0
 

Author Comment

by:ccllww
ID: 14071315
thank you. that is perfect.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 14071385
no worries - happy to help:)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question