2 Replies Latest reply on Aug 7, 2007 7:49 PM by James Newton, ACP

    Create a child cast member

    PDiLalla Level 1
      Hi,

      I need to create a dynamic menu for an application. Right now I am creating every item as a new cast member:

      newMember = new(#text)
      member(newMember).name = "Item1"
      member(newMember).text = "Blabla"

      What I would like to do, is have an existing cast member with the good font, font size, color, etc... and in my lingo script, create all my new cast members based on the existing one, so I would only need to change the text it contains and not the color, size....

      It could also be usefull to do this since I could attach a behavior to the existing cast member and then all my new ones would have the same behavior attached to them.

      I hope this can be done, sorry if it is obvious, I'm in the process of learning Director and Lingo.

      Thanks,
      Pat
        • 1. Re: Create a child cast member
          Level 7
          Hi Pat, and welcome to the list.

          As for your question, I'd suggest you work with a single cast in general,
          unless it really helps organizing your project.
          Creating members on the fly -as it seems you are doing- is a much cleaner
          approach.
          Why don't you create a handler that would accept as arguments the formatting
          options and the member they should be applied to?
          Or e.g. two handlers that each would apply some fixed formatting to a member
          that is passed to it.
          The less the members, the smaller the project, btw.

          > It could also be useful to do this since I could attach a behavior to the
          > existing cast member
          I suppose you are talking about cast member scripts, not behaviors. Another
          thing you'd better avoid, since behaviors (scripts attached to sprites) are
          more flexible, receive notifications that script members don't (like e.g. on
          beginSprite), and are designed for oop (a reference to the script
          object -me- is passed as the first argument by the system when calling
          behaviors' handlers).


          "PDiLalla" <webforumsuser@macromedia.com> wrote in message
          news:f97p50$rh1$1@forums.macromedia.com...
          > Hi,
          >
          > I need to create a dynamic menu for an application. Right now I am
          > creating
          > every item as a new cast member:
          >
          > newMember = new(#text)
          > member(newMember).name = "Item1"
          > member(newMember).text = "Blabla"
          >
          > What I would like to do, is have an existing cast member with the good
          > font,
          > font size, color, etc... and in my lingo script, create all my new cast
          > members
          > based on the existing one, so I would only need to change the text it
          > contains
          > and not the color, size....
          >
          > It could also be usefull to do this since I could attach a behavior to the
          > existing cast member and then all my new ones would have the same behavior
          > attached to them.
          >
          > I hope this can be done, sorry if it is obvious, I'm in the process of
          > learning Director and Lingo.
          >
          > Thanks,
          > Pat
          >


          • 2. Re: Create a child cast member
            James Newton, ACP Level 3
            You can create a copy of an existing text member, and then set its text as follows:

            vMemberNum = member("Existing Text Member Name").duplicate()
            vNewMember = member(vMemberNum)
            vNewMember.text = "New text"