4 Replies Latest reply on Jun 9, 2006 2:16 PM by sbryner

    My First Function

    sbryner Level 1
      Hello,

      I'm trying to create what I think would be a very basic button.

      I want to enlarge an _mc when onRollOver occurs and decrease when onRollout occurs.
      So below is the function I created for enlarging it and making it smaller.
      can somebody tell me what I'm doing wrong?

      this code:

      home_mc.onRollOver = function () {
      home_mc._xscale=_xscale + 10;
      home_mc._yscale=_yscale + 10;
      }

      works for a single _mc but what if I want to have many of them do this?

      should I set some how:

      btnName = mcName;
      mcName._xscale=_xscale + 10;

      thanks,




        • 1. Re: My First Function
          I tried Level 1
          You are having a scoping problem when you are inside your functions. For example, when you are in the onRollOver event, you are calling enLarge. However, the code inside that function doesn't know about enLarge unless you tell it. Most get around the problem this way.

          var owner = this;

          home_mc.onRollOver = function () {
          owner.Enlarge(this);
          }

          Hope this helps
          Robert
          • 2. Re: My First Function
            sbryner Level 1
            Do I need the var owner=this;

            what about this?

            function enLarge (btnName) { //name the function and set my variable

            eval(btnName)._xscale =_xscale + 10; //eval variable and put into string
            eval(btnName)._yscale =_yscale + 10;//eval variable and put into string


            about_mc.onRollover = function () {
            enLarge("about_mc"); // on rollover sets the enLarge variable = about_mc

            so wouldn't the eval (btnName) = about_mc and have it called by the
            enLarge function onRollover?

            or do I need to set a .this variable?

            thanks for helping.
            • 3. Re: My First Function
              ufitzi Level 1
              you can set up enLarge/makeSmaller so that they take a MC as an argument. EX:
              function enLarge(mc:MovieClip)
              {
              mc._xscale = 200;
              etc...
              }

              Or, you can generalize the functions so that they work for any button or movieclip. They would look like this:

              function enLarge () {
              _xscale =_xscale + 10;
              _yscale =_yscale + 10;
              }

              and you would "point" your onRollover() method of any MovieClip to these functions. Like so:

              home_mc.onRollOver = enLarge;
              In the latter case, you're setting your user defined function as the value of a MovieClips onRollover method.

              Hope this gives you an idea of how functions work.
              Remember, a function, or method, is like a variable (_xscale, _y), in that it's value can be changed or updated. That's how #2 works. By attaching a function to a movie clip or button, the properties that function moifies are specific to that MovieClip object or Button object, since we kept the code generalized, as opposed to using instance names.
              • 4. Re: My First Function
                sbryner Level 1
                Thanks all.

                I got it to work don't know how... guess that's what I'm learning for.

                thanks again,