2 Replies Latest reply on Aug 11, 2007 5:41 PM by askmrkelly

    On/Off button

    askmrkelly Level 1
      I have a button which changes cast member when selected as well as navigate to a marker, but I also want it to function as an on/off switch for a film loop. I have an flame (in the form of an animated film loop) which I want to be able to turn off and on when I select the button.

      I have determined I cannot use the blend property for the film loop, but I have used the loc to change the location of the sprite to off the stage, then back on when I need it. The issue is actually making this button into an on/off switch so when the user selects it, the flame turns on, but when the user selects it again the flame turns off. I still want to maintain the integrity of my navigation in the movie as well as my member rollovers. Is this even possible?

      I have looked in the Lingo dictionary in regards to the _mouse.mouseDown property, maybe setting this up as an if else statement, but I am not sure as to how this would be written or whether or not this is the right procedure.

      Thanks in advance.
        • 1. Re: On/Off button
          James Newton, ACP Level 3
          Right-click or Ctrl-click on the flame filmloop sprite, and select "Behaviors..." from the contextual menu which appears. The Behavior Inspector will open. click on the + icon at the top left corner of the window to create a new behavior on the sprite. Call the new behavior "Hide Sprite". At top right of the Behavior Inspector, you will find a Script Window icon. Click on this.

          In the Script Window which opens, paste the following lines of code:

          -- HIDE SPRITE BEHAVIOR --

          property pSprite -- this sprite
          property pVisibleLoc -- initial loc of this sprite
          property pHiddenLoc -- loc of this sprite where it is entirely
          -- off-stage

          on beginSprite(me) --------------------------------------------
          -- ACTION: Remembers the sprite's initial position on-stage
          -- and calculates a position off-stage to which it
          -- can be move to hide it.
          -------------------------------------------------------------

          pSprite = sprite(me.spriteNum)
          pVisibleLoc = pSprite.loc

          -- Determine how far to move the sprite off-stage to the left
          vOffset = pSprite.right - pSprite.locH
          pHiddenLoc = pVisibleLoc.duplicate()
          pHiddenLoc.locH = -vOffset
          end beginSprite


          on ToggleVisible(me, isVisible) -------------------------------
          -- INPUT: <isVisible> should be TRUE or FALSE. If it is
          -- neither, FALSE is assumed
          -- ACTION: Shows the sprite at its original loc if isVisible
          -- is TRUE. Moves it off-stage if not.
          -------------------------------------------------------------

          if isVisible = TRUE then
          pSprite.loc = pVisibleLoc
          else
          pSprite.loc = pHiddenLoc
          end if
          end ToggleVisible


          In the Property Inspector at the Sprite tab, name the sprite "Flame".

          Now select your button. Follow the steps above to add a new behavior to the button sprite. This time, paste the following code into the Script window that opens:


          property pOn -- TRUE or FALSE depending on whether the Flame sprite is visible or not


          on beginSprite me
          pOn = TRUE
          end beginSprite


          on mouseUp me
          pOn = not pOn

          sendSprite("flame", #ToggleVisible, pOn)
          end mouseUp
          • 2. Re: On/Off button
            askmrkelly Level 1
            WOW! Thanks - it worked perfectly. I am really going to have to sit down and read through it several times so I understand it all.