Skip to main content
Arioman
Inspiring
November 9, 2012
Question

AS2 to AS3 music on-off movieclip button

  • November 9, 2012
  • 1 reply
  • 210295 views

hi

i have a nice music on-off button , it`s a equalizer that dancing and when you click on it`s turn to down (mute)

but it`s in as2 !!

now i work on AS3 and i need this in my project

however maybe some users not use FlashCS5 so i put AS2 script here ...

onClipEvent (load)

{

    _root.soundstatus = "on";

    _root.mySound = new Sound(_level0);

    _root.mySound2 = new Sound(_level1);

    _root.mySound3 = new Sound(_level2);

    _root.mySound4 = new Sound(_level3);

    _root.mySound5 = new Sound(_level4);

    maxvolume = 100;

    minvolume = 0;

}

onClipEvent (enterFrame)

{

    if (_root.soundstatus == "on")

    {

        step = 5;

    } // end if

    if (_root.soundstatus == "off")

    {

        step = -5;

    } // end if

    maxvolume = maxvolume + step;

    if (maxvolume > 100)

    {

        maxvolume = 100;

    } // end if

    if (maxvolume < 0)

    {

        maxvolume = 0;

    } // end if

    _root.mySound.setVolume(maxvolume);

    _root.mySound2.setVolume(maxvolume);

    _root.mySound3.setVolume(maxvolume);

    _root.mySound4.setVolume(maxvolume);

    _root.mySound5.setVolume(maxvolume);

}

in another spirite

onClipEvent (load)

{

    n = int(Math.random() * this._totalframes);

    this.gotoAndPlay(n);

}

if it`s too hard to convert

can anyone tell me How i can make a 2 function button in AS3 ????


for example i want ON button to set music on and when click on it o want this button turn to off and set sound mute !!  ( when click on off again the sound will be on again )

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 9, 2012

You should look into the AS3 Sound class if that is what you intend to be using.  There should be tutorial information available if you use search terms like "AS3 Sound tutorial".

As far as the dual function button goes, you can use boolean logic to decide whether the button will be starting or stopping the sound.  Just as an example, the AS2 code you show has a "soundstatus" variable that you could use to decide whether the button needs to start or stop the sound...

if(soundstatus == "on"){

     // code to stop the sound

} else {

     // code to start the sound

}

Arioman
AriomanAuthor
Inspiring
November 9, 2012

thanks Mr.Murphy

as my bad chance i search around internet and only some useful tutorial about controling sound with various Icons like : stop , play , pause , forward .

as i say i want to create 2 functional button to do that , i need only one button that when click it sound goes to mute and show off and then when i click again the sound play again and my button rollback to first .

i dont know maybe i must use movieclip button and use gotoandplay function with some sound function together to do this ,,,

i will be try ...

but i wish someone can help me to solve this sooner