0 Replies Latest reply on Apr 27, 2011 2:53 PM by maxxiejw

    Multiple MovieClips with same instance name

    maxxiejw

      I'm following a tower defence tutorial and part of the code is set up so I can build towers on the "grass" movie clip. I wanted to add more patches of "grass" and gave them all the same instance name so I can be able to place towers on them, but I have the problem that I can only place towers on the first item I placed and has the instance name of "grass". I can't seem to place towers on the other patches of grass.

      I removed the instance name of the first patch of grass and it let me build towers on the second patch, but the second patch only.

       

      I was following this tutorial: http://www.goofballgames.com/2010/01/31/how-to-build-a-tower-defense-f lash-game-part-2-placing-towers/

       

       

       

      Here is the code for it I believe:

      onClipEvent (load)
      {
          active = 0;
      }

      onClipEvent (enterFrame)
      {
          if (active == 1)
          {
              setProperty("", _x, int((_root._xmouse - 10) / 20) * 20 + 20);
              setProperty("", _y, int((_root._ymouse - 10) / 20) * 20 + 20);
       
        hitTestOnGrassMovieClip = _root.grass.hitTest(_x, _y, 1);
       
              if (hitTestOnGrassMovieClip) {
                  gotoAndStop(1);
         _root.ranger.gotoAndStop(1);
              }
              else {
                  gotoAndStop(2);
         _root.ranger.gotoAndStop(2);
              }
       
              _root.ranger._x = _x;
              _root.ranger._y = _y;
              _root.ranger._width = _root["tower_" + tower].range * 2;
              _root.ranger._height = _root["tower_" + tower].range * 2;
          }
      }


      on (press)
      {
      hitTestOnGrassMovieClip = _root.grass.hitTest(_x, _y, 1);
      hitTestOnDeSelectMovieClip = _root.deselect.hitTest(_x, _y, 1);

          if (hitTestOnGrassMovieClip || hitTestOnDeSelectMovieClip) {
              if (hitTestOnGrassMovieClip) {
         ++_root.towerCount;
         _root["tower_" + tower].duplicateMovieClip("t" + _root.towerCount, 500 + _root.towerCount);
         a = _root["t" + _root.towerCount];
         a._x = _x;
         a._y = _y;
         a.active = 1;
        }
       
        active = 0;
        setProperty("", _x, 1000);
        _root.selectedTower = "";
        _root.ranger._x = 1000;
        _root.ranger._width = 10;
        _root.ranger._height = 10; 
          }
      }