Skip to main content
Inspiring
December 29, 2012
Answered

Call to a possibly undefined method stop through a reference with static type.flash.media.Sound

  • December 29, 2012
  • 1 reply
  • 3445 views

This error appears when I tried putting this code 'soundFx_1.stop();' inside a rollOut function. What does this mean?

This topic has been closed for replies.
Correct answer kglad

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. >.<


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();

       

}

1 reply

kglad
Community Expert
Community Expert
December 29, 2012

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.

Inspiring
December 29, 2012

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?

kglad
Community Expert
Community Expert
December 29, 2012

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.