3 Replies Latest reply on Jul 15, 2006 8:37 AM by injpix

    Trouble using variable to get mc property

    ricklecoat
      I'm creating a rollover effect for a collection of 12 mcs so that on mouseover the clip grows a little bit. This involves locating the x and y coordinates each clip, and to do so I've tried to farm the job out to a few variables and one function, so that the onRollOver event simply sets the variables and calls the function.

      It's not working. Flash seems to be implying that I can't use a variable (string type) to get a property -- ie. variable._x rather than myInstanceName._x

      Is this correct, or is my error elsewhere?
      Hope you can help.

      (By the way, there will of course be an onRollOut event as well. Just getting this bit to work first.)

      Thanks;
      Rick

      (Here's the code):
        • 1. Re: Trouble using variable to get mc property
          injpix Level 3
          Need to use the square brackets to avoid compile errors.

          // SET UP VARIABLES
          var clipPositionx:Number = 0;
          var clipPositiony:Number = 0;
          var clipName:String = "";

          // FUNCTION TO BE CALLED
          function rolloverClip() {
          clipPositionx = this[clipName]._x;
          clipPositiony = this[clipName]._y;

          trace("clipPositionx >>> "+clipPositionx);
          trace("clipPositiony >>> "+clipPositiony);

          this[clipName]._xscale = 110;
          this[clipName]._yscale = 110;
          this[clipName]._x = clipPositionx - 4;
          this[clipName]._y = clipPositiony - 4;
          }

          // ROLLOVER ACTIONS
          claire_mc.useHandCursor = true;
          claire_mc.onRollOver = function() {
          clipName = "claire_mc";
          rolloverClip();
          }
          • 2. Re: Trouble using variable to get mc property
            ricklecoat Level 1
            Ah, that's great, thanks.
            I had a feeling that it would be a syntax problem, and it's nice to know that my solution was at least more or less on the right track. I'm knew to Actionscript and, as (basically) a non-coder, it's a steep learning curve. Even the tiniest glimmer of success is welcome!

            Thanks for the pointer.
            • 3. Re: Trouble using variable to get mc property
              injpix Level 3
              When using brackets to do what you are doing can be frustrating if you are not aware on how to use them especially when you start nested movieclips. Below I have several variations on ways to do it and ways not to do it. I am using a variable ( i ) to show how it is done by dynamically referencing a movieclip. My rule-of-thumb are the following when using brackets ( [ ] );

              1. Encapsulate ONLY ONE movieclip with brackets.
              2. Never have a dot next to the outer left bracket.
              3. Always have a dot next to the outer right bracket when accessing a movieclip’s property.

              For the first part of code I have a movieclip on stage with an instance name of “ball3_mc”. For the second part of the code I have a movieclip named “ballholder_mc” that now contains ‘ball3_mc’ inside of it. I hope this helps.