3 Replies Latest reply on Apr 17, 2006 3:22 AM by James Newton, ACP

    property script NickN4m3

    NickN4m3
      whats wrong with this script?----
      I am trying to create a switch button. When you click on it, an object rotate but if you click again it stops...
      theres something wrong, maybe i don't understand the function of "Property"

      -- my script written in the button image-object

      property switchy

      on beginsprite
      switchy = TRUE
      on mouseup
      switchy = not(switchy)

      on exitframe
      if switchy = TRUE then sprite(2).rotation = sprite(2).rotation + 10
      if switchy = FALSE then sprite(2).rotation = 0
      end if

      end
        • 1. Re: property script NickN4m3
          James Newton, ACP Level 3
          Your script works fine, so long as there is a sprite in channel 2 which supports the rotation property. #shape and #filmloop members (for example) are not affected by changes to the sprite's rotation.

          I've rewritten your behavio slightly. This version rotates the sprite that it is attached to, and this remains in its rotated position when you click a second time:

          property pSprite -- sprite to which this behavior is attached
          property pRotate -- boolean. If TRUE, sprite rotates

          on beginsprite(me)
          pSprite = sprite(me.spriteNum)
          pRotate = TRUE
          end beginSprite

          on mouseup(me)
          pRotate = not pRotate
          end mouseUp

          on exitframe
          if pRotate then
          pSprite.rotation = pSprite.rotation + 10

          --else
          -- pSprite.rotation = 0
          end if
          end exitframe
          • 2. Re: property script NickN4m3
            Level 7
            I assume this is a behavior script attachd to the button sprite.
            Properties don't work with movie scripts.


            You might end up with the ration stuck at 360, I don't think it wraps
            when incrementing beyone 360


            you could try using mod, perhaps something like

            if switchy = TRUE then sprite(2).rotation = (sprite(2).rotation + 10(
            mod 360
            • 3. Re: property script NickN4m3
              James Newton, ACP Level 3
              The maximum rotation of a sprite is 21474836.47 or (the maxInteger) / 100.0.

              If you rotate the sprite 10° sixty times a second, it will stop rotating after just under an hour.