2 Replies Latest reply on Apr 17, 2006 6:17 AM by Newsgroup_User

    Instance name being used as movie clip text

    mac_monkey Level 1
      Hi, I have a button that I want to have set functions, but I want it to contain dynamic text so that whatever the name of the instance, it is also the text of that instance...so my standard button could be used in an instance called hello-where the text is hello and an instance called goodbye where the text is goodbye.

      Any suggestions welcome
        • 1. Re: Instance name being used as movie clip text
          mac_monkey Level 1
          Oh and I'll also want to associate different values to variables in each instance of the button. Is there any easy way to do this...I mean I'm a little confused by the whole structure of the timelines and symbols and stuff. I don't want to assign a variable to the instance and find it's assigned it to the button and hence all instances of the button. Where would I put the variables that just relate to that instance, but can be refered to in the button.

          If you see what I mean...I want to set some variables in each of the instances that a standard method in the button reads in different values depending on the instance.
          • 2. Re: Instance name being used as movie clip text
            Level 7
            mac monkey,

            >> Hi, I have a button that I want to have set functions, but
            >> I want it to contain dynamic text so that whatever the
            >> name of the instance, it is also the text of that instance...

            All right. The text part is unrelated to the part about assigning
            functions. Let's take them one at a time. Your subect line speaks of
            "movie clip text," so I'll assume your button is a MovieCip instance (that
            is, a movie clip symbol), not a Button instance.

            Give your movie clip an instance name by selecting it on the Stage and
            looking to the Property inspector. Let's say you choose the instance name
            theClip. Make sure the dynamic text field also has an instance name (we'll
            say theField). Then, from a keyframe in the timeline that contains the
            movie clip (which, in turn, contains your text field), type the following:

            theClip.theField.text = theClip._name;

            What's happening here? Well, look up the class entries for MovieClip
            and TextField, and you'll see. We're using the MovieClip._name property to
            retrieve the movie clip's instance name and we're using the TextField.text
            property to set the dynamic text field's textual content. (As an aside,
            class entries in the ActionScript Language Reference are your best bet a a
            first stop for research. Classes define object, and just about everything
            in ActionScript is an object. Properties are an object's characteristics;
            methods are the things an object can do; events are the things an object can
            react to.)

            To assign functions to a movie clip-based button, look up the MovieClip
            class events.

            theClip.onRelease = function() {
            // put your instructions here
            }

            >> so my standard button could be used in an instance
            >> called hello-where the text is hello and an instance
            >> called goodbye where the text is goodbye.

            That'll do it. I don't know what you mean by "standard button"; perhaps
            you're speaking of a Button instance. If that's it, the same principle
            applies, but I should mention that I cannot seem to set dynamic text inside
            a Button instance (a button symbol). I'm not saying it cannot be done --
            I'm actually surprised that I can't -- but a movie clip button handles this
            just as nicely.

            > Oh and I'll also want to associate different values to
            > variables in each instance of the button.

            Not sure what you're asking.

            > Is there any easy way to do this...I mean I'm a little
            > confused by the whole structure of the timelines and
            > symbols and stuff.

            The MovieClip class is arguably the most important class to learn, since
            even the main timeline (the published SWF itself) is a movie clip.

            > I don't want to assign a variable to the instance and
            > find it's assigned it to the button and hence all instances
            > of the button.

            You don't want to "assign a variable to the instance" -- *what*
            instance? If you put ActionScript inside the timeline or a given symbol,
            then all instances of that symbol will contain that ActionScript. If you
            scope variables, functions, and the like to your instances as I described
            above, the code will only apply to the instance(s) you choose.

            > Where would I put the variables that just relate to that
            > instance, but can be refered to in the button.

            In a keyframe of the timeline that holds your instance. Just use the
            instance name to direct your ActionScript.


            David
            stiller (at) quip (dot) net
            Dev essays: http://www.quip.net/blog/
            "Luck is the residue of good design."