Copy link to clipboard
Copied
This error appears when I tried putting this code 'soundFx_1.stop();' inside a rollOut function. What does this mean?
you're not stopping any sound in your mouseover listener function, only your rollover listener function:
...
var soundFx_2:Sound = new Sound(new URLRequest("Cabinet_Close.mp3"));
var soundFx_3:Sound = new Sound(new URLRequest("Cabinet_Open.mp3"));
var sc: SoundChannel;
Cabinet1_00.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
Cabinet1_00.addEventListener(MouseEvent.ROLL_OUT, fl_RollOutHandler);
if (this['showAcid3'] == null)
{
var showAcid3:Boolean = true;
}
Copy link to clipboard
Copied
the sound class does not have a stop() method. you must define a soundchannel when your sound starts and apply stop() to that soundchannel instance:
var sc:SoundChannel=soundFx_1.play();
//in your listener function:
sc.stop();
p.s. please mark helpful/correct responses.
Copy link to clipboard
Copied
It doesn't work. I might as well explain my problem. I have 2 function, the RollOut and MouseOver function. I have a cabinet that uses this two function. When I mouseOver to the cabinet, the cabinet will open and when I remove the mouse, the cabinet will close. Inside the cabinet movieclip, there are items that I have placed inside it so that when I mouseOver it to the cabinet, the items will be seen. My problem is, when I mouseOver to those items inside the cabinet, the sound effects that I used in MouseOver function plays. Is there a way to make the sound effect not play when I mouseOver to this item?
Copy link to clipboard
Copied
that code works unless you misapplied it.
show the code you used to create soundFx_1, the soundchannel and the code you used to stop the soundchannel.
Copy link to clipboard
Copied
Here it is:
var soundFx_2:Sound = new Sound(new URLRequest("Cabinet_Close.mp3"));
var soundFx_3:Sound = new Sound(new URLRequest("Cabinet_Open.mp3"));
var sc: SoundChannel = soundFx_3.play();
Cabinet1_00.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
Cabinet1_00.addEventListener(MouseEvent.ROLL_OUT, fl_RollOutHandler);
if (this['showAcid3'] == null)
{
var showAcid3:Boolean = true;
}
showAcid3 = true;
function fl_MouseOverHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Open_0')
soundFx_3.play();
setChildIndex(Cabinet1_00, numChildren -1);
if (showAcid3 == true)
{
Cabinet1_00.Acid_3.gotoAndStop('Still');
Cabinet1_00.Acid_3.addEventListener(MouseEvent.CLICK, removeSelf);
}
else
{
Cabinet1_00.Acid_3.visible = false;
}
}
function removeSelf(e:MouseEvent):void
{
showAcid3 = false;
soundFx_1.play();
DisplayObject(e.target).removeEventListener(MouseEvent.CLICK, removeSelf);
}
function fl_RollOutHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Still');
soundFx_2.play();
sc.stop();
}
Copy link to clipboard
Copied
use:
var soundFx_2:Sound = new Sound(new URLRequest("Cabinet_Close.mp3"));
var soundFx_3:Sound = new Sound(new URLRequest("Cabinet_Open.mp3"));
var sc: SoundChannel = soundFx_3.play();
Cabinet1_00.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
Cabinet1_00.addEventListener(MouseEvent.ROLL_OUT, fl_RollOutHandler);
if (this['showAcid3'] == null)
{
var showAcid3:Boolean = true;
}
showAcid3 = true;
function fl_MouseOverHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Open_0')
sc=soundFx_3.play();
setChildIndex(Cabinet1_00, numChildren -1);
if (showAcid3 == true)
{
Cabinet1_00.Acid_3.gotoAndStop('Still');
Cabinet1_00.Acid_3.addEventListener(MouseEvent.CLICK, removeSelf);
}
else
{
Cabinet1_00.Acid_3.visible = false;
}
}
function removeSelf(e:MouseEvent):void
{
showAcid3 = false;
soundFx_1.play();
DisplayObject(e.target).removeEventListener(MouseEvent.CLICK, removeSelf);
}
function fl_RollOutHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Still');
soundFx_2.play();
sc.stop();
}
Copy link to clipboard
Copied
The problem still occurs. >.< In addition to that, soundFx_3 plays after exporting the swf.
Copy link to clipboard
Copied
it plays immediately because that's what you coded. if you don't want it play immediately, don't apply play() to your sound immediately:
var soundFx_2:Sound = new Sound(new URLRequest("Cabinet_Close.mp3"));
var soundFx_3:Sound = new Sound(new URLRequest("Cabinet_Open.mp3"));
var sc: SoundChannel;
Cabinet1_00.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
Cabinet1_00.addEventListener(MouseEvent.ROLL_OUT, fl_RollOutHandler);
if (this['showAcid3'] == null)
{
var showAcid3:Boolean = true;
}
showAcid3 = true;
function fl_MouseOverHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Open_0')
sc=soundFx_3.play();
setChildIndex(Cabinet1_00, numChildren -1);
if (showAcid3 == true)
{
Cabinet1_00.Acid_3.gotoAndStop('Still');
Cabinet1_00.Acid_3.addEventListener(MouseEvent.CLICK, removeSelf);
}
else
{
Cabinet1_00.Acid_3.visible = false;
}
}
function removeSelf(e:MouseEvent):void
{
showAcid3 = false;
soundFx_1.play();
DisplayObject(e.target).removeEventListener(MouseEvent.CLICK, removeSelf);
}
function fl_RollOutHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Still');
soundFx_2.play();
sc.stop();
}
Copy link to clipboard
Copied
Oh I see. It doesn't play anymore when I exported the swf but the soundeffect is still playing when I mouseover to the items inside the cabinet movieClip. >.<
Copy link to clipboard
Copied
you're not stopping any sound in your mouseover listener function, only your rollover listener function:
var soundFx_2:Sound = new Sound(new URLRequest("Cabinet_Close.mp3"));
var soundFx_3:Sound = new Sound(new URLRequest("Cabinet_Open.mp3"));
var sc: SoundChannel;
Cabinet1_00.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
Cabinet1_00.addEventListener(MouseEvent.ROLL_OUT, fl_RollOutHandler);
if (this['showAcid3'] == null)
{
var showAcid3:Boolean = true;
}
showAcid3 = true;
function fl_MouseOverHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Open_0');
sc.stop();
sc=soundFx_3.play();
setChildIndex(Cabinet1_00, numChildren -1);
if (showAcid3 == true)
{
Cabinet1_00.Acid_3.gotoAndStop('Still');
Cabinet1_00.Acid_3.addEventListener(MouseEvent.CLICK, removeSelf);
}
else
{
Cabinet1_00.Acid_3.visible = false;
}
}
function removeSelf(e:MouseEvent):void
{
showAcid3 = false;
soundFx_1.play();
DisplayObject(e.target).removeEventListener(MouseEvent.CLICK, removeSelf);
}
function fl_RollOutHandler(event:MouseEvent):void
{
Cabinet1_00.gotoAndStop('Still');
sc.stop();
sc= soundFx_2.play();
}
Copy link to clipboard
Copied
it works now. thank you!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now