3 Replies Latest reply on May 19, 2007 7:43 AM by Shadowhawkserenity

    Cast Member Scripts

    Shadowhawkserenity
      Hi,
      I'm fairly new to Lingo and trying to put a script onto a cast member that will cause the cast member to switch to a different one. I know how to do this with a sprite script, but I'm hoping to do it with a cast member script instead.

      I'm creating a game in which the user pops balloons by clicking on them. I want to attach the script to the cast member instead of the sprite because the cast member will behave the same way every time and I think this will be a more efficient use of lingo. Unfortunately I'm not getting it right and I'm not sure if it can be done. Here is the sprite script that worked:

      on mouseDown
      set the memberNum of sprite 1 to 2
      end

      Cast member 1 is an image of a balloon
      Cast member 2 is an image of a number 1 (the score increment the user gains by popping the balloon)

      the idea is that the score image remains on screen for a brief time (a second or less) and then the user is returned to the game play to click another balloon.

      So...all that to ask a simple question: Is there a way to attach that script to the cast member instead of the script?

      Thanks,
      Shadowhawk's serenity
        • 1. Re: Cast Member Scripts
          Level 7
          " and I think this will be a more efficient use of lingo. "

          No, it will not be a more efficient use of Lingo, but you can indeed attach
          scripts to cast members. Simply right-click (if using Windows) on the cast
          member in the cast window and select the Cast Member Script option from the
          menu.

          "Shadowhawkserenity" <webforumsuser@macromedia.com> wrote in message
          news:f2kv6p$386$1@forums.macromedia.com...
          > Hi,
          > I'm fairly new to Lingo and trying to put a script onto a cast member that
          > will cause the cast member to switch to a different one. I know how to do
          > this
          > with a sprite script, but I'm hoping to do it with a cast member script
          > instead.
          >
          > I'm creating a game in which the user pops balloons by clicking on them.
          > I
          > want to attach the script to the cast member instead of the sprite because
          > the
          > cast member will behave the same way every time and I think this will be a
          > more
          > efficient use of lingo. Unfortunately I'm not getting it right and I'm
          > not
          > sure if it can be done. Here is the sprite script that worked:
          >
          > on mouseDown
          > set the memberNum of sprite 1 to 2
          > end
          >
          > Cast member 1 is an image of a balloon
          > Cast member 2 is an image of a number 1 (the score increment the user
          > gains by
          > popping the balloon)
          >
          > the idea is that the score image remains on screen for a brief time (a
          > second
          > or less) and then the user is returned to the game play to click another
          > balloon.
          >
          > So...all that to ask a simple question: Is there a way to attach that
          > script
          > to the cast member instead of the script?
          >
          > Thanks,
          > Shadowhawk's serenity
          >


          • 2. Re: Cast Member Scripts
            Level 7
            As Dave mentioned, no, this is not more efficient. You don't explain a
            lot about your design, but, here are a few of the reasons why writing
            modular code and attaching it to sprites is a better, and ultimately,
            simpler method.

            If you write code directly to a cast member, then that code will only
            work for that member. So, if you have one red balloon member, for
            instance, and you want to write code that will control that member's
            sprite, you will have unique code for that member. If you want a second
            red balloon, then you have to repeat the whole process: make a second
            member and write unique code for it. You will have to repeat this
            process for every balloon in the movie.

            Now you have to place the instances of each of these members on the
            stage. If you get any of them in the wrong sprite channel, the code
            won't work correctly.

            With this method, you will need to make 10 unique cast members to have
            10 sprites on the stage. Most of a Director movie's file size is based
            on the bitmap members' size. So, more members, bigger file.

            If you use standard Director authoring methods, you can create one
            balloon member, place as many instances on the stage as you need and
            then attach a single behavior to each sprite instance. Each sprite will
            know its own channel number, so that won't need to be assigned. You can
            color each of the sprites using Lingo, so you only need one original
            member.

            --
            Rob
            _______
            Rob Dillon
            Adobe Community Expert
            http://www.ddg-designs.com
            412-243-9119

            http://www.macromedia.com/software/trial/
            • 3. Re: Cast Member Scripts
              Shadowhawkserenity Level 1
              Thank you, Rob!! That changes everything. I didn't know I could color the balloons using lingo! *scrambles for her manuals* I kind of figured there was a reason it wasn't easy to put that code on the cast member but I tend to do things the hard way so...

              Dave, thank you for taking some time to answer my question. I know how to access the script for a cast member, I was talking about the syntax of the code itself though.

              *heads back to the drawing board*
              Thanks again, gentlemen!