4 Replies Latest reply on May 23, 2006 4:59 PM by Craigus86

    Movie clip trouble

    Craigus86
      i have 25 movie clips in a grid 5x5, when i click on one it changes colour. I want to be able to click on one and then drag over the others and have them change colour. It sounds simple but i can't get it to work. The movie clips are all duplicated from one movie clip and called Tile1, Tile2, Tile3 etc
      The code i'm using is within the movie clip (because it needs to be duplicated as well) and all Tiles are refered to using "this" so which ever movie clip i click on "this" refers to it, which is my problem because all the code now only refers to one Tile.

      I have been able to get the exact oppsite of what i want using "onRollOver" this colours all the tiles while the mouse left mouse button is not held and when i press and hold the left mouse button it stops colouring Tiles, what i want is when i hold the mouse down it colours them and stops when i release the mouse button.

      I have tried using onMouseDown but it works differently to onRollOver, It ends up colouring all tiles as soon as the mouse is clicked.

      Any ideas?

      Hope this makes sense
        • 1. Re: Movie clip trouble
          kglad Adobe Community Professional & MVP
          initiate a loop on startDrag() and continually use a hitTest in a for-loop to check which rolled-over tiles to color.
          • 2. Re: Movie clip trouble
            Craigus86 Level 1
            hi kglad,

            I do not want to move the tile, so i can't use startDrag().

            hitTest would be good if i can use it to see if the cursor touches the tile. is this possible?
            Is there a way to get onRollOver to work when the Left Mouse button is held down?
            Is there a way to use on(MouseOver) for a mc?

            • 3. Re: Movie clip trouble
              kglad Adobe Community Professional & MVP
              you don't need to use a loop and hitTest then. you can set a variable's value that's dependent upon the tile you press. then define onDragOver behaviors for all your tiles that let's them do whatever based on that variable's value.
              • 4. Movie clip trouble
                Craigus86 Level 1
                Kglad,
                I tried what you said but the problem is, when i click and hold one tile the code then only refers to that tile. So if i click and hold on one tile then drag over it, it changes but the others don't because the mouse is still pressed down which makes that tile the active one because the code uses 'this' which refers to the active tile. here is the code if that helps.

                |--------------Scene1--------------|
                var MapSize:Number = 16;
                stop();

                Scene1_OK_btn.onPress = function() {
                MapSize = int(Input_Map_Size.text)
                play();
                }
                |----------------Scene1------------------|


                |-----------------Scene2----------------|
                stop();
                var MapCentreX:Number = 480;
                var MapCentreY:Number = 240;
                var ToolCentreX:Number = 480;
                var ToolCentreY:Number = 540;
                var TilePosX = 0;
                var TilePosY = ((MapSize*(-15))+15);
                var DirtToggle = "off"
                var GridToggle = "on"
                var DragToggle = "off"
                var AniToggle = "on"
                var RotateArrayX:Array = Array(MapSize*MapSize);
                var RotateArrayY:Array = Array(MapSize*MapSize);

                //----------------------------------------------------------------------------//

                this.attachMovie("Map", "Map", -5000, {_x:MapCentreX, _y:MapCentreY}); //attaches the map mc that will contain all the tiles
                this.attachMovie("Tool", "Tool", 5000, {_x:ToolCentreX, _y:ToolCentreY}); //attaches the tool bar
                this.Map.attachMovie("Ani_Rotate", "Ani_Rotate", -6000, {_x:0, _y:0}); //attaches the animation of the map rotation
                Map.Ani_Rotate._width = (MapSize * 60); //resizes the animation to the selected size of the map
                Map.Ani_Rotate._height = (MapSize * 30); //resizes the animation to the selected size of the map
                // the below code attaches all the tiles into the map mc
                for (var i:Number = 1; i <= MapSize; i++) {
                for (var j:Number = 1; j <= MapSize; j++) {
                Map.attachMovie("Tile", ("Tile" + (((i*MapSize)-MapSize)+j)), (((i*MapSize)-MapSize)+j), {_x:TilePosX, _y:TilePosY});
                //trace("Tile"+(((i*MapSize)-MapSize)+j)+"._y = "+ eval("Map.Tile" + (((i*MapSize)-MapSize)+j))._y);
                TilePosX -= 30;
                TilePosY += 15;

                };
                TilePosX = (i*30);
                TilePosY = (((MapSize*(-15))+15) + (i*15));
                };

                //----------------------------------------------------------------------------//

                // ENTER FRAME
                onEnterFrame = function() {
                if (Map.Ani_Rotate._currentframe == 15 or Map.Ani_Rotate._currentframe == 65 or AniToggle == "off") {
                for (var i:Number = 1; i <= (MapSize*MapSize); i++) {
                eval("Map.Tile" + (i))._x = RotateArrayX[i-1]
                eval("Map.Tile" + (i))._y = RotateArrayY[i-1]
                };
                };
                if (Map.Ani_Rotate._currentframe == 50 or Map.Ani_Rotate._currentframe == 100) {
                Map.Ani_Rotate.swapDepths(-6000);
                Map.Ani_Rotate.gotoAndStop(1);
                };
                };
                // ENTER FRAME

                // ZOOM IN/OUT
                Map.onMouseWheel = function(delta) {
                if (delta > 0 and Map._xscale > 30) {
                Map._xscale -= 35;
                Map._yscale -= 35;
                }else if (delta < 0 and Map._xscale < 590){
                Map._xscale += 35;
                Map._yscale += 35;
                };
                };
                Mouse.addListener(Map);
                // ZOOM IN/OUT

                // TOGGLE GRID ON/OFF
                Tool.Tool_Grid.onPress = function() {
                if (Map.Tile1.Tile_Grid._alpha == 0) {
                var a = 100;
                GridToggle = "on"
                }else{
                var a = 0;
                GridToggle = "off"
                };
                for (var i:Number = 1; i <= (MapSize*MapSize); i++) {
                eval("Map.Tile" + (i)).Tile_Grid._alpha = a;
                };
                };
                // TOGGLE GRID ON/OFF

                // TOGGLE DIRT ON/OFF
                Tool.Tool_Dirt.onPress = function() {
                if (DirtToggle == "off") {
                DirtToggle = "on"
                } else {
                DirtToggle = "off"
                };
                };
                // TOGGLE DIRT ON/OFF

                // TOGGLE ANIMATION ON/OFF
                Tool.Tool_Ani.onPress = function() {
                if (AniToggle == "on") {
                AniToggle = "off"
                } else {
                AniToggle = "on"
                };
                };
                // TOGGLE ANIMATION ON/OFF

                // ROTATE MAP TO THE LEFT
                Tool.Tool_Left.onPress = function() {
                if (AniToggle == "on") {
                Map.Ani_Rotate.swapDepths(4999);
                Map.Ani_Rotate.gotoAndPlay(52);
                };
                for (var i:Number = 1; i <= MapSize; i++) {
                for (var j:Number = 1; j <= MapSize; j++) {
                RotateArrayX[(((i*MapSize)-MapSize)+j)-1] = eval("Map.Tile" + ((j * MapSize)-(i-1)))._x;
                RotateArrayY[(((i*MapSize)-MapSize)+j)-1] = eval("Map.Tile" + ((j * MapSize)-(i-1)))._y;
                };
                };
                };
                // ROTATE MAP TO THE LEFT

                // ROTATE MAP TO THE RIGHT
                Tool.Tool_Right.onPress = function() {
                if (AniToggle == "on") {
                Map.Ani_Rotate.swapDepths(4999);
                Map.Ani_Rotate.gotoAndPlay(2);
                };
                for (var i:Number = 1; i <= MapSize; i++) {
                for (var j:Number = 1; j <= MapSize; j++) {
                RotateArrayX[(((i*MapSize)-MapSize)+j)-1] = eval("Map.Tile" + (((MapSize*MapSize)-(j * MapSize))+i))._x;
                RotateArrayY[(((i*MapSize)-MapSize)+j)-1] = eval("Map.Tile" + (((MapSize*MapSize)-(j * MapSize))+i))._y;
                };
                };
                };
                // ROTATE MAP TO THE RIGHT

                |-----------------Scene2---------------|

                |-----------------Tile--------------------|
                //the part you told me to do
                this.onPress = function() {
                _root.DragToggle = "on";
                }
                //this is the onDragOver part you told me to do
                this.onDragOver = function() {
                if (_root.DirtToggle == "on" and _root.DragToggle == "on") {
                this.Tile_Grid.swapDepths(2000); //swaping the depths so the Dirt doesn't cover the grid
                this.Tile_Grass.swapDepths(1000);
                removeMovieClip(this.Tile_Grid);
                removeMovieClip(this.Tile_Grass);
                attachMovie("Tile_Dirt", "Tile_Dirt", -2);
                attachMovie("Tile_Grid", "Tile_Grid", -1);
                if (_root.GridToggle == "off") {
                this.Tile_Grid._alpha = 0; //hide the grid
                };
                };
                };
                |---------------------Tile---------------|


                so from the code above you can see that the one mc Tile is duplicated and therefore so is the code inside.
                Here is a link to the SWF
                Instructions:
                Click the white button to goto the map
                Click the Brown square to turn the DirtToggle on
                click and hold the right mouse button on any tile and then dragoff the tile then DragOver it and it will change
                What i want is when you click and hold one tile any tile you drag over while holding the mouse down will change.

                Thank heaps for your help so far.

                Craig