9 Replies Latest reply on Aug 31, 2008 8:21 AM by robdillon

    Applying a var to a movieclip?

    americancuervo Level 1
      Hello,
      I am looking for some guidance here.

      I am working with this code right now,

      var hasFocus:Number=1;

      mc_1.onPress=function(){
      hasFocus=1
      }

      and I would like to understand how to apply hasFocus=1 to the movieclip mc_1 without using an onPress or onRelease function.

      Please help if you can,
      Thanks
        • 1. Re: Applying a var to a movieclip?
          kglad Adobe Community Professional & MVP
          what do you mean by "applying" variable to a movieclip?
          • 2. Re: Applying a var to a movieclip?
            americancuervo Level 1
            Well, maybe applying isn't the right term to use.

            I am searching for a way to make mc_1 automatically contain "hasFocus = 1".
            Instead of having to use onPress to make it contain "hasFocus = 1".

            This is the code I am using right now.

            var hasFocus:Number=1;

            mc_1.onPress=function(){
            hasFocus=1
            }
            mc_2.onPress=function(){
            hasFocus=2
            }

            btn_mc.onPress=function(){
            if (hasFocus==1){
            gotoAndPlay(2);
            }
            else if (focus==2) {
            gotoAndPlay(3);
            }

            Thanks for any help that you can provide.
            • 3. Re: Applying a var to a movieclip?
              kglad Adobe Community Professional & MVP
              if mc_1 exists when hasFocus is created, it can access that variable. mc_1.onPress isn't doing anything useful.

              i'm pretty sure you've abstracted what you want so what you're posting makes no sense. why don't you explain what you're trying to accomplish?
              • 4. Re: Applying a var to a movieclip?
                americancuervo Level 1
                I apologize for not making sense.

                I want to do something like,
                var hasFocus:Number=1;

                eyez.hasFocus=1
                eyez2.hasFocus=2

                red.onPress=function(){
                if (eyez){
                var color:Color = new Color(eyez);
                var myTransform:Object = color.getTransform();
                var myTransform:Object = {rb: 255, gb: 0, bb: 0};
                color.setTransform(myTransform);
                }
                else if (focus==2) {
                var color:Color = new Color(eyez2);
                var myTransform:Object = color.getTransform();
                myTransform = {rb: 255, gb: 0, bb: 0};
                color.setTransform(myTransform);
                }
                }
                • 5. Re: Applying a var to a movieclip?
                  americancuervo Level 1
                  Sorry I made a mistake in the last code.

                  eyez.hasFocus=1
                  eyez2.hasFocus=2

                  red.onPress=function(){
                  if (focus==1){
                  var color:Color = new Color(eyez);
                  var myTransform:Object = color.getTransform();
                  var myTransform:Object = {rb: 255, gb: 0, bb: 0};
                  color.setTransform(myTransform);
                  }
                  else if (focus==2) {
                  var color:Color = new Color(eyez2);
                  var myTransform:Object = color.getTransform();
                  myTransform = {rb: 255, gb: 0, bb: 0};
                  color.setTransform(myTransform);
                  }
                  }

                  Thanks
                  • 6. Re: Applying a var to a movieclip?
                    americancuervo Level 1
                    And just one more time for good measure.
                    Never giving up.


                    var hasFocus:Number=1;

                    eyez.hasFocus=1
                    eyez2.hasFocus=2

                    red.onPress=function(){
                    if (hasFocus=1){
                    var color:Color = new Color(eyez);
                    var myTransform:Object = color.getTransform();
                    var myTransform:Object = {rb: 255, gb: 0, bb: 0};
                    color.setTransform(myTransform);
                    }
                    else if (hasFocus=2) {
                    var color:Color = new Color(eyez2);
                    var myTransform:Object = color.getTransform();
                    myTransform = {rb: 255, gb: 0, bb: 0};
                    color.setTransform(myTransform);
                    }
                    }
                    • 7. Re: Applying a var to a movieclip?
                      kglad Adobe Community Professional & MVP
                      your code makes no sense. try explaining in words what you want to do.

                      (and your last code snippet fails to use == as the comparison operator (which is correctly used in the message just above your last message).
                      • 9. Re: Applying a var to a movieclip?
                        robdillon Most Valuable Participant
                        If you declare a variable, as you did with "var hasFocus:Number=1;", then that variable's value is available anywhere that you use the name of the variable.

                        If you want to create a variable that belongs to a particular object, like this: "eyez.hasFocus=1", then you are creating a property of that object. It belongs to that object and that object only. It is completely different from and has no relationship to the variable in "var hasFocus:Number=1;".

                        For clarity you want to give your variables unique names so that there is less confusion. When you are setting the value of a variable you use the single equal "=", when you want to evaluate, read, the variable's value, you use the double equal "==".

                        It will be nearly impossible for anyone to help you with the code that you show in this thread without seeing the code in your previous thread on the same subject.