Skip to main content
Inspiring
October 24, 2011
Answered

volumebar

  • October 24, 2011
  • 2 replies
  • 867 views

i add to horizontal volumebar in my player.

But compiler error msg is...

Scene 1, Layer 'Actions', Frame 1, Line 6051061: Call to a possibly undefined method setVolume through a reference with static type flash.media:Sound.

and mouse moving not correct in this script. how to change code.

var myGlobalSound:Sound = new Sound();

var  mDown = Boolean;

var soundVol;

controlBar.volume_bar.addEventListener(MouseEvent.MOUSE_DOWN, volumeonPress)

controlBar.volume_bar.addEventListener(MouseEvent.MOUSE_UP, volumeonRelease)

                                                                                            

function volumeonPress(Event:MouseEvent):void

{

    mDown = true;

    controlBar.volume_bar.volMC.width = controlBar.volume_bar.mouseX;

    soundVol = 100 * controlBar.volume_bar.volMC.width / controlBar.volume_bar.maxVol.width;

    myGlobalSound.setVolume(soundVol);

}

function volumeonRelease(Event:MouseEvent):void

{

          mDown = false;

          videocontrols.volOn_mc.visible=true;

}

videocontrols.volume_bar.addEventListener(MouseEvent.MOUSE_UP, volbarClick)

videocontrols.volume_bar.addEventListener(MouseEvent.MOUSE_MOVE, volMove);

function volbarClick(Event:MouseEvent):void

{

    mDown = false;

    stage.removeEventListener(MouseEvent.MOUSE_UP, volumeonRelease);

}

function volMove(Event:MouseEvent):void

{

    if (mDown)

    {

        videocontrols.volume_bar.volMC.width = videocontrols.volume_bar.mouseX;

    }

    if (videocontrols.volume_bar.volMC.width >= videocontrols.volume_bar.maxVol.width)

    {

        videocontrols.volume_bar.volMC.width = videocontrols.volume_bar.maxVol.width;

    }

    if (videocontrols.volume_bar.volMC.width <= 1)

    {

        videocontrols.volume_bar.volMC.width = 1;

    }

 

    soundVol = 100 * (videocontrols.volume_bar.volMC.width - 1) / videocontrols.volume_bar.maxVol.width;

    myGlobalSound.setVolume(soundVol);

    Event.updateAfterEvent();

}

videocontrols.volOn_mc.addEventListener(MouseEvent.CLICK, volumeOn);

videocontrols.volOff_mc.addEventListener(MouseEvent.CLICK, voumelOff);

function volumeOn(Event:MouseEvent):void

          {

               videocontrols.volOff_mc.visible = true;

                 videocontrols.volOn_mc.visible = false;

               videocontrols.volume_bar.volMC.width = 0;

               myGlobalSound.setVolume(0);

          }

 

function voumelOff(Event:MouseEvent):void

          {

               videocontrols.volOn_mc.visible=true;

                videocontrols.volOff_mc.visible=false;

               videocontrols.volume_bar.volMC.width = 20;

               myGlobalSound.setVolume(50);

          }

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

use soundTransform property of NetStream.

2 replies

Inspiring
October 24, 2011

As the error says, there is no such thing as setVolume on Sound. Use SoundTransform class to change volume:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundTransform.html

If you use FLVPlayback - it has volume property as well.

Inspiring
October 24, 2011

i am not using flvplayback

Andrei1-bKoviICorrect answer
Inspiring
October 24, 2011

use soundTransform property of NetStream.

Inspiring
October 24, 2011

videocontrols = controlBar