Copy link to clipboard
Copied
I have researched on YouTube and through this support forum to try to understand how to do this, but I cannot get it to work. Does anyone know of a way to do this with actionscript, perhaps in the most simple form possible please?
var s:Sound = new S(); // where S is the class (=linkage id in library panel) of your sound
var sc:SoundChannel = s.play();
var s_bool:Boolean = true;
toggle_button.addEventListener(MouseEvent.CLICK,toggle_soundF);
function toggle_soundF(e:MouseEvent):void{
if(s_bool){
sc.stop();
} else {
sc=s.play();
}
s_bool=!s_bool;
}
Copy link to clipboard
Copied
var s:Sound = new S(); // where S is the class (=linkage id in library panel) of your sound
var sc:SoundChannel = s.play();
var s_bool:Boolean = true;
toggle_button.addEventListener(MouseEvent.CLICK,toggle_soundF);
function toggle_soundF(e:MouseEvent):void{
if(s_bool){
sc.stop();
} else {
sc=s.play();
}
s_bool=!s_bool;
}
Copy link to clipboard
Copied
Apologies, but I get the message "Call to a possibly undefined method s". Its refering to the part where it says new S.
I put the song name like the following:
var s:Sound = new S("Motivator.mp3");
I assume I am doing something incorrectly?
Copy link to clipboard
Copied
Is there any text in the Linkage column in the library? If there is, it's quite likely you put Motivator in there. If you did, the line should read:
var s:Sound = new Motivator();
Copy link to clipboard
Copied
This was a great help. Thanks!
Copy link to clipboard
Copied
This helped a bunch. I'll be sure to credit you, thank you.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
I'm trying to use this in an HTML5 canvas. Where do I add this code, just to a frame with symbol in it, or how is it supposed to work?
Copy link to clipboard
Copied
that's actionscript which won't work in canvas. you need to use javascript/createjs, SoundJS v1.0.0 API Documentation : SoundJS
Copy link to clipboard
Copied
is it possible fadeIn and fadeOut the sound when toggle the button? can you give the example with .fla file maybe, thanks
Copy link to clipboard
Copied
as3 or javascript?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now