Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Dec 28, 2012 Dec 28, 2012

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

TOPICS
ActionScript
3.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 29, 2012 Dec 29, 2012

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;

          }

  

...
Translate
Community Expert ,
Dec 28, 2012 Dec 28, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 28, 2012 Dec 28, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 28, 2012 Dec 28, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 28, 2012 Dec 28, 2012

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 28, 2012 Dec 28, 2012

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 28, 2012 Dec 28, 2012

The problem still occurs. >.< In addition to that, soundFx_3 plays after exporting the swf.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 28, 2012 Dec 28, 2012

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 28, 2012 Dec 28, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012

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

       

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2012 Dec 29, 2012

it works now. thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines