2 Replies Latest reply on Jul 3, 2009 7:23 AM by wkirklutz

    Using Dynamic Names for MovieClips

    wkirklutz

      I am trying to simplify things by using dynamic MovieClip names. I have three MovieClips on the stage.

      1) mcPage1

      2) mcPage2a

      3) mcPage2b

       

      But my code isn't working. I'm guessing the "this" part is what is messing it up. Thinking that the computer doesn't know which MC is "this". It traces fine outside the function, but inside the function it traces undefined.

       

      stop();

      // import tween classes

      import mx.transitions.Tween;

      import mx.transitions.easing.*;

      //

      if (firsttime<>1) {

      _global.MiddleOfPage = (Stage.width/2);

      _global.OnPage = 1;

      _global.NextPage = _global.OnPage+1;

      firsttime = 1;

      }

      //         

      _global.PageFlipSpeed = .5;

      //

      // Following Flips Page Forward

      //

      trace(this["mcPage"+_global.OnPage]);

      trace(this["mcPage"+_global.NextPage+"a"]);

      trace(this["mcPage"+_global.NextPage+"b"]);

      //trace(this["mcPage"+(_global.NextPage)+"b"])

      this["mcPage"+_global.OnPage].onRelease = function() {

      trace("Inside Function: "+this["mcPage"+_global.OnPage]);

      trace("Inside Function: "+this["mcPage"+_global.NextPage+"a"]);

      trace("Inside Function: "+this["mcPage"+_global.NextPage+"b"]);

      //

      this["mcPage"+_global.NextPage+"b"]._alpha = 100;

      //

      var Animation:Object;

      //

      Animation = new Tween(this["mcPage"+_global.OnPage], "_xscale", Regular.easeInOut, 100, 0, _global.PageFlipSpeed, true);

      Animation = new Tween(mcClick, "_alpha", Regular.easeInOut, 100, 0, _global.PageFlipSpeed, true);

      //

      Animation.onMotionFinished = function() {

      Animation = null;

      var Animation2:Object;

      Animation2 = new Tween(this["mcPage"+_global.NextPage+"a"], "_xscale", Regular.easeInOut, 0, 100, _global.PageFlipSpeed, true);

      Animation2 = new Tween(this["mcPage"+_global.NextPage+"a"], "_x", Regular.easeInOut, _global.MiddleOfPage, 0, _global.PageFlipSpeed, true);

      //

      Animation2.onMotionFinished = function() {

      Animation2 = null;

      nextFrame();

      };

      };

      };

        • 1. Re: Using Dynamic Names for MovieClips
          kglad Adobe Community Professional & MVP

          only use the _global prefix when assigning a value to a variable that you want to make global, not when retrieving that value.

           

          otherwise:

           

          this["mcPage"+_global.OnPage]

           

          should work IF mPage1 etc is defined on the current timeline/scope.

          • 2. Re: Using Dynamic Names for MovieClips
            wkirklutz Level 1

            Figured it out. I needed to put those values in Variables:

             

            stop();

            // import tween classes

            import mx.transitions.Tween;

            import mx.transitions.easing.*;

            //

            if (firsttime<>1) {

            _global.MiddleOfPage = (Stage.width/2);

            _global.OnPage = 1;

            _global.NextPage = _global.OnPage+1;

            firsttime = 1;

            }

            //             

            _global.PageFlipSpeed = .5;

            //

            // Following Flips Page Forward

            //

            Page = this["mcPage"+_global.OnPage];

            PageA = this["mcPage"+_global.NextPage+"a"];

            PageB = this["mcPage"+_global.NextPage+"b"];

            //

            Page.onRelease = function() {

            //

            PageB._alpha = 100;

            //

            var Animation:Object;

            //

            Animation = new Tween(Page, "_xscale", Regular.easeInOut, 100, 0, _global.PageFlipSpeed, true);

            Animation = new Tween(mcClick, "_alpha", Regular.easeInOut, 100, 0, _global.PageFlipSpeed, true);

            //

            Animation.onMotionFinished = function() {

            Animation = null;

            var Animation2:Object;

            Animation2 = new Tween(PageA, "_xscale", Regular.easeInOut, 0, 100, _global.PageFlipSpeed, true);

            Animation2 = new Tween(PageA, "_x", Regular.easeInOut, _global.MiddleOfPage, 0, _global.PageFlipSpeed, true);

            //

            Animation2.onMotionFinished = function() {

            Animation2 = null;

            nextFrame();

            };

            };

            };