1 Reply Latest reply on Mar 16, 2011 12:33 PM by ctaminian

    AS2 - Taking squares which are adjacent

    daranianandthegang

      Hi, I am currently working on a college project and need some help with my flash, I am very new to Flash so please bare with me

       

      What I am trying to acheive is some sort of interactive interface, what I have so far is a 3x3 grid and 2 drag objects, what I have done so far is when you drag one of the drag objects of a square into the grid, depending on the colour of the drag object it will change to that colour, here is the code that I have used for that (it can probably be simplified but I don't know how ).

       

      Drag object code.

       

      on (press) {
          this.startDrag();
      }

       

      //Target one
      on (release) {
          stopDrag();
          this._x = 45.00
          this._y = 48.00
          if (eval(this._droptarget) == _root.target1) {
              _root.target1.gotoAndStop(2);
          }
      }
      //Target two
      on (release) {
          stopDrag();
          if (eval(this._droptarget) == _root.target2) {
              _root.target2.gotoAndStop(2);
          }
      }
      //Target three
      on (release) {
          stopDrag();
          if (eval(this._droptarget) == _root.target3) {
              _root.target3.gotoAndStop(2);
          }
      }

       

      (This repeats another six times, each time the instance name is changed)

       

      Each one of the grid pieces is an individual MC with three frames in it, each frame is a different coloured square. What I want to acheive is for you to only be able to make a square the same colour if it is adjacent to a square which is coloured the same.

       

      Example

       

      Start          True          False

       

      1 0 0     1 1 0     1 0 1

      0 0 0     1 0 0     0 1 0

      0 0 0     0 0 0     0 0 0

       

      0 = not coloured

      1 = colour 1

       

       

      I thought about using an if(eval() statment but I couldn't figure it out, I then thought about make a True and False statment but I couldn't figure that out either.

       

      Any help will be VERY appreciated, thanks for your time.

       

      Daranian and the Gang!

        • 1. Re: AS2 - Taking squares which are adjacent
          ctaminian

          Its pretty hard to see what you are trying to achieve here...

           

          But from what I understand you need to create variables for each color inside your targets...

           

          Then check to see if one target's color is blue for instance then change the color of another target...

           

          Inside each one of your target movieclips create variables for your colors:

           

          So if your target1 is originally blue in color do this inside the target1

           

          var blue = true;      // target1 on first frame is color blue

          var green = false;    // target1 on second frame is color green

          var red = false;       // target1 on third frame is color red

           

          Then to check a target's color, use this:

           

          If (target1.blue == true)

          {

                   target2.gotoAndStop(1);        // frame1 of target2 is a blue square

                   target2.blue = true;

          }

           

          Hope this helps