Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Sound On/Off Button; Loop; Autoplay

  1. #1

    Sound On/Off Button; Loop; Autoplay

    I'm almost done building a full flash site where it navigates by position of timeline.

    I just need a simple on/off button for a soundloop to loop and play automatically. the on/off button just simply turns it off (toggle is optional). on it doesn't have to resume, just start the pool again.

    actionscript 3.0 in cs3 please

  2. #2
    You could maybe do it something like this. (.fla attached)

    import flash.media.Sound;
    import flash.media.SoundChannel;
    var soundOn:Boolean = true; //music is ON when we start
    var myMusic:TitleMusic = new TitleMusic();
    var myChannel:SoundChannel = myMusic.play(0,1000); // endless loop, in effect
    var myTransform:SoundTransform;
    mySoundButton.buttonMode = true;
    mySoundButton.mouseChildren = false;
    function toggleSound(e:MouseEvent)
            // turn sound off
            myTransform = new SoundTransform();
            myTransform.volume = 0; // silent
            myChannel.soundTransform = myTransform;
            soundOn = false;
            mySoundButton.myButtonText.text = "click to turn sound ON";
        else // sound is off
            // turn sound on
            myTransform = new SoundTransform();
            myTransform.volume = 1; // full volume
            myChannel.soundTransform = myTransform;
            soundOn = true;
            mySoundButton.myButtonText.text = "click to turn sound OFF";

  3. #3
    OK, let's try that 'fla attached' thing once more ...
    Attached Files Attached Files

  4. #4
    thanks diamonddog, i'll take a look at it when i get off work... major thanks!

  5. #5

    little adaptation to the ON OFF button

    i was like crazy searching on the web for a simple solution.
    i found this post, i studied the attachments and here is my problem solved and customized

    I just wanted an ON / OFF button to control volume of a sound on a clip... (both actions on same button)
    no one but YOU dear DiamondDog, knew how to do it on AS3... everyone else knew HOWTO on as2.

    Here is my code and my attached file of example.

    NOTE: I USED FUNCTIONS AND JACK DOYLE´S TweenMax Engine for animation.

    /// Created by Fernando Valbuena --->  http://fernando.uk.to  ///
    import gs.TweenMax;
    import gs.easing.*
    function encendido() {
    TweenMax.to(es1, 0.3, {scaleY:-5, yoyo:true});
    TweenMax.to(es2, 0.5, {scaleY:-5, yoyo:true});
    TweenMax.to(es3, 0.4, {scaleY:-5, yoyo:true});
    TweenMax.to(es4, 0.3, {scaleY:-5, yoyo:true});
    TweenMax.to(es5, 0.2, {scaleY:-5, yoyo:true});
    TweenMax.to(sonido1, 1, {volume:1, delay:0.5});
    function apagado() {
    TweenMax.to(es1, 0.3, {scaleY:0, yoyo:false});
    TweenMax.to(es2, 0.5, {scaleY:0, yoyo:false});
    TweenMax.to(es3, 0.4, {scaleY:0, yoyo:false});
    TweenMax.to(es4, 0.3, {scaleY:0, yoyo:false});
    TweenMax.to(es5, 0.2, {scaleY:0, yoyo:false});
    TweenMax.to(sonido1, 1, {volume:0, delay:0.5});
    var sonido:Boolean = true;
    encendidoapagado.buttonMode = true;
    encendidoapagado.mouseChildren = false;
    function toggleSound(e:MouseEvent)
      sonido = false;
      sonido = true;
    Attached Files Attached Files

  6. #6
    Do you also have the code for an volumeslider with the On/Off button??

    I just cant seem to figure out how to to that..


  7. #7

    I'm new to as3 and I am trying to put one main on/off button for ALL of my sound on my site. How do you mute multiple sound files with one button action. I don't have a main background music file to mute. Thank you DiamondDog for your file. It makes sense if I just had one mp3 file to mute but I am confused with the other sounds I have to mute too. I've been searching the net for hours for an answer but I am not getting anywhere. I am just getting more frustrated. If someone could be of help on here, that would be wonderful.

    Thank you very much!

  8. #8

    Thats great

    Thanks for this guys, it's been a big help. I've been sitting here for hours tryna figure this one out. Though i do have one question, and it's probably a stupid one but i dont know much about flash. In diamonds code above, how do I put my own soundtrack in? I've tried importing to the library and changing "TitleMusic" to the name of my file but it comes up with the error:
    1046: Type was not found or was not a compile-time constant: Gametheme.

  9. #9
    Registered User
    pococksama, I too had the same problem of getting my sound to play. I looked closely at DiamondDog's .fla and noticed the properties of "TitleMusic". You can view Properties of the symbols by double-clicking or right-mouse clicking. For reference, I am using Flash CS4.

    First, you have to turn on the "Linkage" area, make sure these fields are checked:
    Export for ActionScript
    Export in frame 1

    Then the Class and Base class fields will open up. These fill in by themselves as:

    They have green check marks which indicate they work I suppose. Try it out!

  10. #10
    How would I loop with this code? I tried the above, but got errors. Thanks!

    //imports the necessary as events
    import flash.events.Event
    import flash.events.MouseEvent;

    var isPlaying:Boolean = new Boolean();
    var pausePosition:Number = new Number();

    //Create an instance of the Sound class
    var soundClip:Sound = new Sound();
    //Create a new SoundChannel Object
    var sndChannel:SoundChannel = new SoundChannel();

    //Load sound using URLRequest
    soundClip.load(new URLRequest("rapid.mp3"));
    //Create an event listener that wll update once sound has finished loading
    soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);

    controller.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);

    function onComplete(evt:Event):void {
    //Play loaded sound
    sndChannel = soundClip.play();
    isPlaying = true;

    function btnPressController(evt:MouseEvent):void
    case true:
    pausePosition = sndChannel.position;
    isPlaying = false;
    case false:
    sndChannel = soundClip.play(pausePosition);
    isPlaying = true;

    function btnPressStop(evt:MouseEvent):void
    pausePosition = 0;
    isPlaying = false;

  11. #11

    How to auto-play with this?:

    function playMusic(e:Event):void



    It`s the code for a Play Button but i need to auto start.


  12. #12
    You might want to check out the SoundMixer class in AS3? For some control its better to use that.

    Joel Tong
    Visit my Flash Website @ www.joeltong.org
    and Flash blog @ www.joeltong.org/blog/

  13. #13
    Hey thanx for the file..but one prblm

    Can u plz add the FUNCTIONS AND JACK DOYLE´S TweenMax Engine for animation.

    The FLA wont run without these. plz help...

  14. #14
    Thanks DiamondDog, your code example really helped me understand how to script this particular function. I do wonder however, is it possible to make the stop action actually stop the sound file and return it back to the begining of the sound track? so that if you click the play button again, the music starts from the begining.

  15. #15
    Thank you VERY MUCH - sorry for the caps but I've been looking for a solution to this CS3 sound problem for hours. It seems like everyone and their brother knows how to do it in AS2. I realize this is an old thread, but to everyone who helped: a huuuge thanks!!!

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012