3 Replies Latest reply on May 6, 2009 10:53 AM by kglad

    Passing MC not as good as hard coded

    StupidHuman

      I've got a transition after clicking on a moie clip that goes like this:

       

      var scale = 800;
      var speed = 61790;
      onEnterFrame = setInterval(fadeFrame,100,mcName);
      function fadeFrame(mc:MovieClip)
      {
          mc._alpha -=5;
          if(mc._alpha <= 0)
          {
          mc.alpha = 0;
          gotoAndStop(houseNumber);
          }
      };

       

      The mcName variable is a Movieclip delared in the first frame, and set with the name of a movieClip in the onRelease of a button instance:

       

          _root.mcName = adjustable1;
          _root.gotoAndStop(2);

       

      It does take the variable into the FadeFrame function, but doesn't work.  It comes out in trace as undefined with the _alpha property.  If I hard code the movieClip name into the setInteval it has no problem.  Any reason why it doesn't want to operate on the movieClip alpha this way?

        • 1. Re: Passing MC not as good as hard coded
          kglad Adobe Community Professional & MVP

          your first problem is with:

           

          onEnterFrame = setInterval(fadeFrame,100,mcName);

           

          that should be something like:

           

          fadeFrameI = setInterval(fadeFrame,100,mcName);

           

           

          your 2nd problem, if you decide to use setInterval(), is you must clear it:

           

          if(mc._alpha<0){

          // do whateveer

          clearInterval(fadeFrameI);

          }

           

          third, it's not clear you're executing that code on the _root timeline.  if you're not, you should use _root.mcName, instead of mcName to pass to fadeFrame().

          • 2. Re: Passing MC not as good as hard coded
            StupidHuman Level 1

            The onEnterFrame worked find when I had the instance name of the movieClip hard coded rather than passing a variable(mcName) into the setInterval.

             

            Even when explicitly setting the _root.mcName when calling setInterval, it doesn't function properly.  A trace confirms it is getting the movie clip.  The movie clip is attached in the onRelease function before the gotoAndStop() that is sending the file into this frame.

            • 3. Re: Passing MC not as good as hard coded
              kglad Adobe Community Professional & MVP

              show your corrected code.