10 Replies Latest reply on Feb 6, 2011 8:58 AM by kglad

    tracking of movieclip

    forsakenedsj

      Hello, im doing a FlashLite 2.1, now have following code.

       

      stop();
      fscommand2 ("SetSoftKeys", "", "Quit Game");

       

      Key.removeListener (myListener);

       

      var myListener:Object = new Object ();
      myListener.onKeyDown = function ()
      {
          var keyCode = Key.getCode ();
          if (keyCode == ExtendedKey.SOFT2)
          {
              gotoAndStop("Quit");
          }
      };

       

      Key.addListener (myListener);

       

      // on load red turn
      turn = "red";
      buildboard();
      var ball:Number;

       

      // set focus on redzone_mc's s_1

      // user only can navigate on redzone only not blue. up down only.

      if (turn == "red")
      {
          Selection.setFocus(s_1);
          s_7.enabled = false;
          s_8.enabled = false;
          s_9.enabled = false;
          s_10.enabled = false;
          s_11.enabled = false;
          s_12.enabled = false;
      }
      else if (turn == "blue")
      {
          Selection.setFocus(s_7);
          s_1.enabled = false;
          s_2.enabled = false;
          s_3.enabled = false;
          s_4.enabled = false;
          s_5.enabled = false;
          s_6.enabled = false;
      }

       

      //onLoad 3 marbles each

       

      function buildboard ()
      {
          _root.ballred.gotoAndStop("0b");
          _root.ballblue.gotoAndStop("0b");
          _root.container.gotoAndStop("0b");
          _root.ball1.gotoAndStop("3b");
          _root.ball2.gotoAndStop("3b");
          _root.ball3.gotoAndStop("3b");
          _root.ball4.gotoAndStop("3b");
          _root.ball5.gotoAndStop("3b");
          _root.ball6.gotoAndStop("3b");
          _root.ball7.gotoAndStop("3b");
          _root.ball8.gotoAndStop("3b");
          _root.ball9.gotoAndStop("3b");
          _root.ball10.gotoAndStop("3b");
          _root.ball11.gotoAndStop("3b");
          _root.ball12.gotoAndStop("3b");
      }

       

      i'm doing a game called Mancala (Cong kak).

       

      // ball1 - ball12 all are movieclips which has at least 36 marbles inside. so onLoad, i make all movieclip stop at "3b", which is labelled. now I need to do the following sequence.

      Example. inside ball1 got 3 balls, click ball1, become 0 ball, it will go to ball2 and drop 1 ball, den go to ball3 to drop 1 ball, den go to ball4 to drop 1 ball...

       

      have done this following code:

       

      bowl1.onPress = function()
      {
          selectedItem = this;
          _root.ball1.gotoAndStop("0b");
          _root.ball2.gotoAndStop("4b");
          _root.ball3.gotoAndStop("4b");
          _root.ball4.gotoAndStop("4b");
          turn = "blue";
      }

       

      but i cant be doing this for all 12 movieclips so have source for help and did this:

       

      var bowlList:Array = [ball1,ball2,ball3,ball4,ball5,ball6,ball7,
                            ball8,ball9,ball10,ball11,ball12];
      function movestones(bowlIndex)
      {
          var numStones = bowlList[bowlIndex]._currentframe-1;
          for (;numStones>0;numStones--)
          {
              //place stone
          }
      }
      s_1.onPress = function()
      {
          movestones(0);
      }

       

      but have no idea wd to do for //place stone.. anyone could help me? thanks lot!

        • 1. Re: tracking of movieclip
          kglad Adobe Community Professional & MVP

          i don't understand:

           

          Example. inside ball1 got 3 balls, click ball1, become 0 ball, it will  go to ball2 and drop 1 ball, den go to ball3 to drop 1 ball, den go to  ball4 to drop 1 ball...

          • 2. Re: tracking of movieclip
            forsakenedsj Level 1

            Erm, there's a game called Mancala, or cong kak.

             

            onLoad the board will appear 3 marbles each.

             

            [12] [11] [10] [09] [08] [07]

            [01] [02] [03] [04] [05] [06]

            and assume above is the board, is red's turn. so navigation at [01]. user can navigate up or down key to select which one to "pick" up and "throw" to other holes in anticlockwise direction.

             

            Example:

            - user click [01], inside [01] become 0 marble, so user have 3 marbles to put at [02][03][04], one each.  [02][03][04] have 4 each after throwing

            - user click [02], inside [02] become 0 marble, so user have 3 marbles to put at [03][04][05], one each. [03][04][05] have 4 each after throwing

             

            the code i did so far helps to track the last ball, but doesn't do the adding stone effect...

            • 3. Re: tracking of movieclip
              kglad Adobe Community Professional & MVP

              :

               


               

              stop();
              fscommand2 ("SetSoftKeys", "", "Quit Game");

               

              Key.removeListener (myListener);

               

              var myListener:Object = new Object ();
              myListener.onKeyDown = function ()
              {
                  var keyCode = Key.getCode ();
                  if (keyCode == ExtendedKey.SOFT2)
                  {
                      gotoAndStop("Quit");
                  }
              };

               

              Key.addListener (myListener);

               

              // on load red turn
              turn = "red";
              buildboard();
              var ball:Number;

               

              // set focus on redzone_mc's s_1

              // user only can navigate on redzone only not blue. up down only.

              if (turn == "red")
              {
                  Selection.setFocus(s_1);
                  s_7.enabled = false;
                  s_8.enabled = false;
                  s_9.enabled = false;
                  s_10.enabled = false;
                  s_11.enabled = false;
                  s_12.enabled = false;
              }
              else if (turn == "blue")
              {
                  Selection.setFocus(s_7);
                  s_1.enabled = false;
                  s_2.enabled = false;
                  s_3.enabled = false;
                  s_4.enabled = false;
                  s_5.enabled = false;
                  s_6.enabled = false;
              }

               

              //onLoad 3 marbles each

               

              function buildboard ()
              {
                  _root.ballred.gotoAndStop("0b");
                  _root.ballblue.gotoAndStop("0b");
                  _root.container.gotoAndStop("0b");
                  _root.ball1.gotoAndStop("3b");
                  _root.ball2.gotoAndStop("3b");
                  _root.ball3.gotoAndStop("3b");
                  _root.ball4.gotoAndStop("3b");
                  _root.ball5.gotoAndStop("3b");
                  _root.ball6.gotoAndStop("3b");
                  _root.ball7.gotoAndStop("3b");
                  _root.ball8.gotoAndStop("3b");
                  _root.ball9.gotoAndStop("3b");
                  _root.ball10.gotoAndStop("3b");
                  _root.ball11.gotoAndStop("3b");
                  _root.ball12.gotoAndStop("3b");
              }

               


               

              bowl1.onPress = function()
              {
                  selectedItem = this;
                  _root.ball1.gotoAndStop("0b");
                  _root.ball2.gotoAndStop("4b");
                  _root.ball3.gotoAndStop("4b");
                  _root.ball4.gotoAndStop("4b");
                  turn = "blue";
              }

               

               

               

              var bowlList:Array = [ball1,ball2,ball3,ball4,ball5,ball6,ball7,
                                    ball8,ball9,ball10,ball11,ball12];
              function movestones(bowlIndex)
              {
                  var numStones = bowlList[bowlIndex]._currentframe-1;
                  for (var i=numStones;i>0;i--)
                  {
                

              bowlList[bowlIndex].prevFrame();
              nextIndex=bowlIndex+i;
              if(nextIndex>12){
              nextIndex=nextIndex%12;
              }
              bowlList[(nextIndex)].nextFrame();

                  }
              }
              s_1.onPress = function()
              {
                  movestones(0);
              }

               

               

              1 person found this helpful
              • 4. Re: tracking of movieclip
                forsakenedsj Level 1

                Hey, it really works what I wanted =) thanks!

                 

                But now you see I have turns: red and blue.

                 

                so the phone onLoad is turn = "red" which as stated in my coding in my post.

                 

                +++ [12] [11] [10] [09] [08] [07] <---- B +++

                +B+                                                  +R+

                +++ [01] [02] [03] [04] [05] [06] <---- R +++

                 

                Legend: B = blue, R = red

                 

                so now is scenario:

                - red's turn, navigations at the red side, if last ball reach its own "home", user will have free turn. if not is blue's turn.

                - blue's turn, navigations at the blue side, if last ball reach its own "home", user will have free turn, if not is red's turn.

                 

                P.S.: both "home" has its own movieclips: blue = ballblue_mc, red = ballred_mc

                 

                How can i do that? I have tried using turn = "red"; on top, and tried it before using my old code but doesn't work..

                 

                if possible can do this additional scenario:

                - red's turn, if [05] or any [..] inside has alot of marbles example got 9 marbles, it will still put marbles at [06], "home", [07], [08], [09], [10], [11], [12], [01]

                // meaning skipping blue's "home".

                - blue turn same...

                • 5. Re: tracking of movieclip
                  kglad Adobe Community Professional & MVP

                  your game is going to get more complicated to encode, especially because of the way you've set it up.  anyway, i don't see any easy way to proceed from where you are and i don't see any easy way to help you without doing all the coding myself.

                  • 6. Re: tracking of movieclip
                    forsakenedsj Level 1

                    oh.. yea I find it very complicated too, thats why source for help =\

                     

                    but is it possible just to add on the turns from the code that u modified? like after last ball den its other turn?

                    • 7. Re: tracking of movieclip
                      kglad Adobe Community Professional & MVP

                      sure.  at the end of the code i suggested (or anywhere you want to toggle the turn variable), you can use:

                       

                      if(turn=="red"){

                      turn="blue";

                      } else {

                      turn="red";

                      }

                      1 person found this helpful
                      • 8. Re: tracking of movieclip
                        forsakenedsj Level 1

                        Hmmm.. it doesn't work. The blue's navigation never shows up at other side after i click any [..] on the red's side... anyways forgot to tell you that ball1 to ball12 are movieclips, below them are buttons so I can call the moveStone function onPress..

                         

                        Is it something affecting it from changing?

                         

                        Cause the button's state OVER is a picture of my navigation

                        • 9. Re: tracking of movieclip
                          kglad Adobe Community Professional & MVP

                          the code i suggested works.  it will toggle the turn variable.  whether that does what you want is a different issue.  you need to do something with that variable to see an on-stage change.

                          • 10. Re: tracking of movieclip
                            forsakenedsj Level 1

                            declared turn as String? have tried using _root.turn but error =\

                             

                            var turn:String;

                            turn = "red";

                             

                            if (turn == "red")

                            {

                            turn = "blue";

                            }

                            else

                            {

                            turn = "red";

                            }