1 Reply Latest reply on Oct 10, 2006 12:58 PM by FasterPastor

    controlling multiple sprites

    JAH_P
      This maybe simple.. maybe hard, but im frustrated and after reading through every lesson and book that i can find... I just cant get this one to work.
      I want to have a button that animates when pressed - kind of like an arm moving a display screen out. Once out, then id like to have an 'x' button to reanimate it back to the original form (closing display screen). How can i get there???

      ps - im not very good with lingo - so id rather not show what i have, just hoping for a restart. Thanks in advance for any help!!
        • 1. controlling multiple sprites
          FasterPastor
          One easy option would be to animate the movement (in and out) on the score, and then set markers in the score to get back and forth (markers are "named" frames, that allow sections of the score to be referred to). Click into the very top track of the score to add new markers. That lets you type a name for a frame to mark the beginning of that "region"). One set of markers could be called "extend screen start" and "extend screen stop" the other set of markers could be called "retract screen start" and "retract screen stop".

          The button in the score, showing on the screen, would be a sprite, showing a cast member that looks like a button. A sprite's member can be changed to another member very easily. To wit:

          sprite(37).member = member("extend_button_image")

          and/or

          sprite(37).member = member("retract_button_image")

          Now, _where_ to implement that? You would have it in a script that would then need to be "attached" to the sprite that displays the button. (That script would become a behavior, ie. a list giving instructions for how its sprite is to behave).

          1. Create a new script.

          2. In the script, put a handler called "on mouseUp me"

          3. Put the needed behavior steps into the mouseUp "handler"

          4. Drag the cast member icon for that script and drop it onto the sprite for the button, as it shows either in the score, or on the stage because of its presence in the score.

          You may need to read about "the frame"...

          The handler would look something like this:

          on mouseUp me
          if the frame < marker("extend screen start") OR the frame > marker("extend screen stop") then
          go to marker("extend screen start")
          sprite(37).member = member("retract_button_image")
          else if the frame > marker("extend screen start") OR the frame < marker("extend screen stop") then
          go to marker("retract screen start")
          sprite(37).member = member("extend_button_image")
          end if
          end if
          end

          A frame script could be set on the end frames of the regions, that says

          On exitFrame me
          go the frame
          end

          That would keep the playhead there until the user clicks to change the location in the score.

          One other idea: You can animate the extension _once_ in the score, and play that animation two ways, both foward and backward, to serve for both the retracting and the extending.

          Let's say that "forward" playback in the score "extends" and "reverse" playback in the score "retracts.

          You would, in the mouseUp script for the button, declare a global variable called "ExtendOrRetract", or something like that, which would be intended to hold either a 1 for extend or a 0 for retract. Then declare the same global variable in the frame script that I will show you below.

          Then, using markers, name the first frame of the animation "Extend" and name the last frame of the animation "Retract"

          Then, in your script for the button (a script with a mouseUp handler for the button), you would put this:

          global ExtendOrRetract
          on mouseUp me
          if ExtendOrRetract then -- same as saying 'if ExtendOrRetract =1'
          go to marker("retract") -- to start reverse animation
          sprite(37).member = member("extend_button_image") -- toggle btn img
          ExtendOrRetract = NOT ExtendOrRetract -- toggle value from 1 to 0
          else -- same as saying if ExtendOrRetract =0
          go to marker("extend") -- to start forward animation
          sprite(37).member = member("retract_button_image")-- toggle btn img
          ExtendOrRetract = NOT ExtendOrRetract -- toggle value from 0 to 1
          end if
          end

          Then, create the following "frame script", and put (drag and drop) this same "frame script" onto each and every frame of the animation in the score:

          global ExtendOrRetract
          on exitFrame me
          if ExtendOrRetract then --same as saying 'if ExtendOrRetract = 1'
          if the frame <> marker "retract" then
          go the frame +1--forward playhead direction to play the animation forward
          else
          if the frame = marker "retract" then -- playhead has reached end of "extend" animation
          go the frame
          end if
          end if
          else -- for this, would be the same as saying ExtendOrRetract = 0
          if the frame <> marker "extend" then
          go the frame -1 --reverse playhead direction to play the animation in reverse
          else
          if the frame = marker "extend" then -- playhead is at end of "retract" animation
          go the frame
          end if
          end if
          end if
          end

          If your animation occupies 10 frames, you would drop this on the first frame of your animation (in the frame script track), and copy it from there, and paste it onto each of the next 9 frames.

          Note: the above code assumes the button sprite is in sprite channel 37 of the score. Change "37" to whatever number channel the button sprite is in.

          Also, you probably will need assign a value to ExtendOrRetract, early on, in a movie script ... like in a prepareMovie script, or perhaps in an 'on beginSprite me' handler, or some such.