6 Replies Latest reply on Nov 30, 2008 12:41 PM by Newsgroup_User

    Mental Block this Sunday Afternoon

    Level 7
      Dear Members of this group,

      If I am creating multiple instances of a button called buy on a movie (e.g.
      buy1 and buy2) and giving each one a different name. How do I get the name
      of the instance clicked? If I use the code below I get the name of the
      original button not the instance name. So easy I presume that I am
      embarrassed asking the group.

      Buy.onPress = function() {
      trace(this._name);
      };

      Thanks.

      Gerry.

        • 1. Re: Mental Block this Sunday Afternoon
          kglad Adobe Community Professional & MVP
          use your button's instance names to define their onPress handlers. eg,

          buy1.onPress = function() {
          trace(this._name);
          };
          • 2. Re: Mental Block this Sunday Afternoon
            Level 7
            kglad,

            Thanks for the reply. I don't think I have given you enough information or
            probably it is just me.

            On a movie I have 2 button instances Buy1 and Buy2 which is based on the
            button Buy. At certain times I want only one of the buttons to work. If the
            user presses Buy1 I would like something to happen but not for the Buy2
            instance.

            I presumed that I would have something behind the Buy button like:

            Buy.onPress = function() {
            trace(this._name);
            if (Evaluate statement) {
            trace("Same");
            }else{
            trace("Not Same");
            }
            };

            (where this._name wiould give me the instance name of the button pressed but
            it gives me Buy!)

            I want to control whether the Buy1 instance works in a given situation or
            Buy2.

            I'm not sure if you are able to help my confused logic.

            Gerry

            "kglad" <webforumsuser@macromedia.com> wrote in message
            news:ggua4t$492$1@forums.macromedia.com...
            > use your button's instance names to define their onPress handlers. eg,
            >
            > buy1.onPress = function() {
            > trace(this._name);
            > };

            • 3. Re: Mental Block this Sunday Afternoon
              kglad Adobe Community Professional & MVP
              the library name (Buy) is irrelevant and cannot be referenced using actionscript.

              instance names can be referenced using actionscript but, since flash 6, instance names (and all other flash objects) are case-sensitive. so, buy1 is not the same as Buy1.
              • 4. Re: Mental Block this Sunday Afternoon
                Rothrock Level 5
                Well what you are saying isn't making any sense. So yeah that is probably it.

                If you have:

                Buy.onPress=function....

                Then that means you have some object with the instance name of "Buy" and you are telling it to give you the name of itself when you press it. That is why it is telling you its instance name. I think you might be confusing library name with instance name a little bit here?

                There is no way that with that code you are doing anything with something called Buy1 and/or Buy2. If you want to work with Buy1 and Buy2 then you need to define event handlers for the events on those buttons.

                There are several ways to do what you are asking. I would probably do something like this:

                Buy1.onPress=sayMyName;
                Buy2.onPress=sayMyName;

                function sayMyName(){
                trace("Pressed: "+this._name);
                switch(this._name){
                case "Buy1":
                // do stuff for Buy1 press
                break;
                case "Buy2":
                // do stuff for Buy2 press;
                break;
                default:
                trace("I don't know what you pressed.")
                }

                }


                • 5. Re: Mental Block this Sunday Afternoon
                  Level 7
                  Rothrock,

                  Thanks for the clarification. I am now much clearer. You have enlightened me
                  this Sunday. Thanks again.

                  Gerry

                  "Rothrock" <webforumsuser@macromedia.com> wrote in message
                  news:gguj7j$eqv$1@forums.macromedia.com...
                  > Well what you are saying isn't making any sense. So yeah that is probably
                  > it.
                  >
                  > If you have:
                  >
                  > Buy.onPress=function....
                  >
                  > Then that means you have some object with the instance name of "Buy" and
                  > you
                  > are telling it to give you the name of itself when you press it. That is
                  > why it
                  > is telling you its instance name. I think you might be confusing library
                  > name
                  > with instance name a little bit here?
                  >
                  > There is no way that with that code you are doing anything with something
                  > called Buy1 and/or Buy2. If you want to work with Buy1 and Buy2 then you
                  > need
                  > to define event handlers for the events on those buttons.
                  >
                  > There are several ways to do what you are asking. I would probably do
                  > something like this:
                  >
                  > Buy1.onPress=sayMyName;
                  > Buy2.onPress=sayMyName;
                  >
                  > function sayMyName(){
                  > trace("Pressed: "+this._name);
                  > switch(this._name){
                  > case "Buy1":
                  > // do stuff for Buy1 press
                  > break;
                  > case "Buy2":
                  > // do stuff for Buy2 press;
                  > break;
                  > default:
                  > trace("I don't know what you pressed.")
                  > }
                  >
                  > }
                  >
                  >
                  >
                  >

                  • 6. Re: Mental Block this Sunday Afternoon
                    Level 7
                    Rothrock,

                    Thanks for the clarification. I am now much clearer. You have enlightened me
                    this Sunday. Thanks again.

                    Gerry

                    "Rothrock" <webforumsuser@macromedia.com> wrote in message
                    news:gguj7j$eqv$1@forums.macromedia.com...
                    > Well what you are saying isn't making any sense. So yeah that is probably
                    > it.
                    >
                    > If you have:
                    >
                    > Buy.onPress=function....
                    >
                    > Then that means you have some object with the instance name of "Buy" and
                    > you
                    > are telling it to give you the name of itself when you press it. That is
                    > why it
                    > is telling you its instance name. I think you might be confusing library
                    > name
                    > with instance name a little bit here?
                    >
                    > There is no way that with that code you are doing anything with something
                    > called Buy1 and/or Buy2. If you want to work with Buy1 and Buy2 then you
                    > need
                    > to define event handlers for the events on those buttons.
                    >
                    > There are several ways to do what you are asking. I would probably do
                    > something like this:
                    >
                    > Buy1.onPress=sayMyName;
                    > Buy2.onPress=sayMyName;
                    >
                    > function sayMyName(){
                    > trace("Pressed: "+this._name);
                    > switch(this._name){
                    > case "Buy1":
                    > // do stuff for Buy1 press
                    > break;
                    > case "Buy2":
                    > // do stuff for Buy2 press;
                    > break;
                    > default:
                    > trace("I don't know what you pressed.")
                    > }
                    >
                    > }
                    >
                    >
                    >
                    >