3 Replies Latest reply on Jul 16, 2007 7:30 PM by kglad

    Can't Get "enabled" to work on Movie Clip In AS3

    backpages
      I'm building simple little mp3 player in AS3. Have been doing it for years in AS2 but decided to learn how in AS3. I want the "play" mc to be disabled upon initial launch of the player, as the music will already be playing. Then when the user clicks "pause" or "stop" the "play" mc will become enabled again. But the code I'm using doesn't seem to disable the "play" mc, you can still click on it and it starts the music a second time. Here's the code I'm using. Any advice would be greatly appreciated. Thanks!

      this.play_mc.buttonMode = true;

      this.play_mc.addEventListener(MouseEvent.MOUSE_OVER, showOverPlay);
      function showOverPlay(myEvent:MouseEvent) {
      play_mc.gotoAndStop("over");
      }

      this.play_mc.addEventListener(MouseEvent.MOUSE_OUT, showNormalPlay);
      function showNormalPlay(myEvent:MouseEvent) {
      play_mc.gotoAndStop("normal");
      }

      this.play_mc.addEventListener(MouseEvent.CLICK, playSound);
      function playSound(myEvent:MouseEvent) {
      myChannel = mySound.play(pausePosition);
      hitPlay();
      }

      this.play_mc.enabled = false;
      this.play_mc.alpha = .5;
        • 1. Re: Can't Get "enabled" to work on Movie Clip In AS3
          SymTsb Level 2
          From the AS3 dictionary

          enabled property

          enabled:Boolean [read-write]

          Language version: ActionScript 3.0
          Player version: Flash Player 9


          A Boolean value that indicates whether a movie clip is enabled. The default value of enabled is true. If enabled is set to false, the movie clip's Over, Down, and Up frames are disabled. The movie clip continues to receive events (for example, mouseDown, mouseUp, keyDown, and keyUp).

          The enabled property governs only the button-like properties of a movie clip. You can change the enabled property at any time; the modified movie clip is immediately enabled or disabled. If enabled is set to false, the object is not included in automatic tab ordering.

          This means you need to remove the event listener for the button when necessary and add it when you need it rather than having it defined 100% of the time.
          • 2. Re: Can't Get "enabled" to work on Movie Clip In AS3
            backpages Level 1
            OK, thanks for the reply. This makes sense in theory, but I can't quite wrap my head around how you would remove a listener from a button. Right now I have defined listeners to move the playhead of the mc to an over state and back to a normal state. I want these to no longer work once the mc is clicked on. And I no longer want it to start to play the sound agin if it is clicked on again. So, how would you tell an mc to remove the event listener from itself when clicked upon? What I've come up with doesn't seem to work. Any suggestions greatly appreciated, or an online tutorial aobut his subjec. Thanks!

            play_mc.addEventListener(MouseEvent.MOUSE_OVER, showOverPlay);
            function showOverPlay(myEvent:MouseEvent) {
            play_mc.gotoAndStop("over");
            }

            play_mc.addEventListener(MouseEvent.MOUSE_OUT, showNormalPlay);
            function showNormalPlay(myEvent:MouseEvent) {
            play_mc.gotoAndStop("normal");
            }

            play_mc.addEventListener(MouseEvent.CLICK, playSound);
            function playSound(myEvent:MouseEvent) {
            myChannel = mySound.play(pausePosition);
            removeEventListener(MouseEvent.MOUSE_OUT, showNormalPlay);
            removeEventListener(MouseEvent.MOUSE_OVER, showOverPlay);
            removeEventListener(MouseEvent.Click, playSound);
            play_mc.alpha = .5;
            }
            • 3. Re: Can't Get "enabled" to work on Movie Clip In AS3
              kglad Adobe Community Professional & MVP
              in your listener's event handler use removeEventListener.