2 Replies Latest reply on Aug 9, 2006 5:36 AM by

    how to specify dynamic moveclip name in an loop ?

      In my flash,
      I add a new layer called actions, and add actionscript at the first frame.
      In the stage, there are 10 instances of "ball" move clips called "ball1_mc" .... to "ball10_mc",
      and 10 intances "city" move clips called "city1_mc" ...to "city10_mc".

      In the script, it seems if I use
      _root.city1_mc.name_txt.Text = "name here", it works ,
      but if I use
      this.city1_mc.name_txt.Text = "name here", it doesn't works .
      What's the difference here?

      Still to add interactive, the following code works
      _root.city1_mc.onRollOver = function()
      {
      _root.city1_mc.gotoAndPlay(2);
      _root.ball1_mc.gotoAndPlay(2)
      };

      _root.city1_mc.onRollOut = function()
      {
      _root.city1_mc.gotoAndPlay(1);
      _root.ball1_mc.gotoAndPlay(1);
      };

      while I want to add these similar code to the 10 instances via loop as the following, it doesn't work either.

      for (var i:Number =1 ; i <= city_number; i++)
      {
      var ballObj:String = "ball" + i +"_mc";
      var cityObj:String = "city" + i +"_mc";

      _root[cityObj].onRollOver = function()
      {
      _root[cityObj].gotoAndPlay(2);
      _root[ballObj].gotoAndPlay("red_slide");
      };
      _root[cityObj].onRollOut = function()
      {
      _root[cityObj].gotoAndPlay(1);
      _root[ballObj].gotoAndPlay(1);
      };
      }

      any help would be great appreciated!
      Thanks!
        • 1. how to specify dynamic moveclip name in an loop ?
          shikozel Level 1
          in the function onRollOver, this will reffer to the buttun that just got clicked
          try to put this code and you will understand it:

          _root[cityObj].onRollOut = function()
          {
          trace(this)
          trace(_root)
          };
          //
          the first tracing will show the intance name of the button.
          the second will show the _root name

          using _root it is not the best practice in my opinion because once you move you movie to another place it wont work. you can do this instead:
          //
          this[cityObj].onRollOut = function()
          {
          this._parent[cityObj].gotoAndPlay(1);
          this._parent[ballObj].gotoAndPlay(1);
          };

          1 person found this helpful
          • 2. Re: how to specify dynamic moveclip name in an loop ?
            Thanks for your reply on the _root and this. i

            But in the loop, still it doesn't work well
            for (var i:Number =1 ; i <= 10; i++)
            {
            var ballObj:String = "ball" + i +"_mc";
            var cityObj:String = "city" + i +"_mc";
            this[cityObj].onRollOver = function()
            {
            this._parent[cityObj].gotoAndPlay(2);
            this._parent[ballObj].gotoAndPlay("red_slide");
            };
            this[cityObj].onRollOut = function()
            {
            this._parent[cityObj].gotoAndPlay(1);
            this._parent[ballObj].gotoAndPlay(1);
            };
            }
            After the loop, it seems when I rollover the every city, the max number ball has the effect which is not correct.
            Thanks.