18 Replies Latest reply on Oct 15, 2010 1:29 AM by dn0myar06

    crossword problem...

    dn0myar06

      im making a cross word game...im actually still starting with this one and i can't figure out how to do this game...

       

      i thought of making dynamic texts to each box and assign letters every time a key is hit....i have a counter to determine which dynamic text to be assign but i'm not sure with the code i'm using...

       

      i tried this code but its not working..hope someone could give me an idea...

       

       

      if (Key.isDown(65 || 97)) {         //this is for letter 'a'
          ctr++;
          if (ctr == 1) {
              char1_1_1 = 'a';               //
      char1_1_1 is the variable name of the first dynamic text
          }
      }

       

      im not so sure how to assign characters to dynamic texts, this is how i do it with integers...

        • 1. Re: crossword problem...
          kglad Adobe Community Professional & MVP

          use the textfield's instance name and assign the text property of your textfield:

           


           

           

          if (Key.isDown(65 || 97)) {         //this is for letter 'a'
              ctr++;  // <- i'm not sure this is what you want

              if (ctr == 1) {  // <- i'm not sure this is what you want
                  char1_1_1TF.text = 'a';               //
          where char1_1_1TF is your textfield's instance name
              }
          }

           

           

          • 2. Re: crossword problem...
            dn0myar06 Level 1

            hi kglad!

             

            should i still use the var name of the textfield in this line??

             

                  char1_1_1TF.text = 'a';

             

            coz' its not working...

            i also tried this:

             

            char1_1_1.TF.text = 'a';    

            _root.char1_1_1TF.text = 'a'; 

            _root.char1_1_1.TF.text = 'a';

            _root.TF.text = 'a'; 

            TF.text = 'a';

             

            but none of them works....

            • 3. Re: crossword problem...
              kglad Adobe Community Professional & MVP

              don't use a textfield variable.  remove everything in the property panel that you have in the variable field for all your textfields.

               

              if assigning a text property doesn't work, it's because you're not using the instance name of your textfield.  to confirm, use:

               

               

              trace(_root.char1_1_1TF);  // which will probably be undefined because you have no such textfield.

               

              to assign a textfield instance name, click on a textfield to select it and in the properties panel, you'll see a field for the instance name.  type one there and make sure there's no variable assigned to the textfield.  retest.

              • 4. Re: crossword problem...
                dn0myar06 Level 1

                ok i removed everything in the var field and put an instance name of c111...

                 

                if (Key.isDown(65 || 97)) {
                        c111.text = 'a';
                }

                 

                this is the code that i'm using, but when i hit 'a'...nothing is showing up in the dynamic field...

                is there something missing in my code??

                • 5. Re: crossword problem...
                  kglad Adobe Community Professional & MVP

                  that if-statement needs to execute when you press a key.  does it?

                  • 6. Re: crossword problem...
                    dn0myar06 Level 1

                    yes..but in this case it doesn't work


                    • 7. Re: crossword problem...
                      kglad Adobe Community Professional & MVP

                      disable keyboard shortcuts if you're testing in the test environment.  and if that doesn't work, show the code you're using.

                      • 8. Re: crossword problem...
                        dn0myar06 Level 1

                        actually this is the only code that i'm still working on:

                        if (Key.isDown(65 || 97/*Key.LEFT*/)) {
                            //ctr++;
                            //if (ctr == 1) {
                                c111.text = 'a';
                            //}
                        }

                        stop();

                         

                        i also tried key left in case 'a' is not working but its not working as well....

                        • 9. Re: crossword problem...
                          kglad Adobe Community Professional & MVP

                          that code won't execute when a key is pressed.  it's just an if-statement that will execute as soon as the playhead enters that frame.

                           

                          use:

                           

                          var kLO:Object = new Object();
                          kLO.onKeyDown = function() {
                            if (Key.isDown(65 || 97)) {
                                  c111.text = 'a';
                              }
                          };

                           

                          Key.addListener(kLO);

                          • 10. Re: crossword problem...
                            dn0myar06 Level 1

                            that works!!!

                             

                            thank you so much!!!

                             

                            • 11. Re: crossword problem...
                              kglad Adobe Community Professional & MVP

                              you're welcome.

                              • 12. Re: crossword problem...
                                dn0myar06 Level 1

                                i'm not really good with functions...is there a way to write this code shorter coz i'm only in my first column with only letters a,b,c clickable and i felt like my code is unnecessarily long....

                                 

                                var kLO:Object = new Object();
                                kLO.onKeyDown = function() {
                                  if (Key.isDown(65 || 97)) {
                                      _root.ctr++;
                                      if (_root.ctr == 1) {
                                      c111.text = 'a';
                                      }
                                      if (_root.ctr == 2) {
                                      c112.text = 'a';
                                      }
                                      if (_root.ctr == 3) {
                                      c113.text = 'a';
                                      }
                                      if (_root.ctr == 4) {
                                      c114.text = 'a';
                                      }
                                      if (_root.ctr == 5) {
                                      c115.text = 'a';
                                      }
                                      if (_root.ctr == 6) {
                                      c116.text = 'a';
                                      }
                                      if (_root.ctr == 7) {
                                      c117.text = 'a';
                                      }
                                      if (_root.ctr == 8) {
                                      c118.text = 'a';
                                      }
                                    }
                                    if (Key.isDown(66 || 98)) {
                                      _root.ctr++;
                                      if (_root.ctr == 1) {
                                      c111.text = 'b';
                                      }
                                      if (_root.ctr == 2) {
                                      c112.text = 'b';
                                      }
                                      if (_root.ctr == 3) {
                                      c113.text = 'b';
                                      }
                                      if (_root.ctr == 4) {
                                      c114.text = 'b';
                                      }
                                      if (_root.ctr == 5) {
                                      c115.text = 'b';
                                      }
                                      if (_root.ctr == 6) {
                                      c116.text = 'b';
                                      }
                                      if (_root.ctr == 7) {
                                      c117.text = 'b';
                                      }
                                      if (_root.ctr == 8) {
                                      c118.text = 'b';
                                      }
                                    }
                                    if (Key.isDown(67 || 99)) {
                                      _root.ctr++;
                                      if (_root.ctr == 1) {
                                      c111.text = 'c';
                                      }
                                      if (_root.ctr == 2) {
                                      c112.text = 'c';
                                      }
                                      if (_root.ctr == 3) {
                                      c113.text = 'c';
                                      }
                                      if (_root.ctr == 4) {
                                      c114.text = 'c';
                                      }
                                      if (_root.ctr == 5) {
                                      c115.text = 'c';
                                      }
                                      if (_root.ctr == 6) {
                                      c116.text = 'c';
                                      }
                                      if (_root.ctr == 7) {
                                      c117.text = 'c';
                                      }
                                      if (_root.ctr == 8) {
                                      c118.text = 'c';
                                      }
                                    }
                                };

                                 

                                Key.addListener(kLO);
                                stop();

                                 

                                 

                                i use "ctr" to count the number of boxes that has been inputed...

                                • 13. Re: crossword problem...
                                  kglad Adobe Community Professional & MVP

                                  if _root.ctr can only be an integer:

                                   

                                  var tl:MovieClip=this

                                  var alphaS:String="abcdefghijklmnopqrstuvwxyz";

                                  var alphaA:Array = alphaS.split("");

                                   

                                  var kLO:Object = new Object();
                                  kLO.onKeyDown = function() {

                                  for(var j:Number=0;j<26;j++){
                                    if (Key.isDown(65+j || 97+j)) {
                                        _root.ctr++;
                                            tl["c"+(110+_root.ctr)].text = alphaA[j];

                                   

                                   

                                  }

                                  }

                                  }

                                  1 person found this helpful
                                  • 14. Re: crossword problem...
                                    dn0myar06 Level 1

                                    very nice code..thanks!!!

                                    • 15. Re: crossword problem...
                                      kglad Adobe Community Professional & MVP

                                      you're welcome.

                                      • 16. Re: crossword problem...
                                        dn0myar06 Level 1

                                        hi! i'm having problem with  the intersection of my cross word puzzle....

                                         

                                        i created mc's in the first box of every number and attached these codes;

                                         

                                        this is the code that i attached in number 2:

                                         

                                        on (release) {
                                        _root.ctr = 0;
                                        y12_mc._alpha = 100;
                                        y11_mc._alpha = 0;
                                        var tl:MovieClip=this
                                        var alphaS:String="abcdefghijklmnopqrstuvwxyz";
                                        var alphaA:Array = alphaS.split("");

                                         

                                        var kLO:Object = new Object();
                                        kLO.onKeyDown = function() {
                                            for(var j:Number=0;j<26;j++){
                                                  if (Key.isDown(65+j || 97+j)) {
                                                  _root.ctr++;
                                                  if (_root.ctr < 5) {                      //number 2 has 4 letters
                                                      if (_root.ctr == 2) {               //i use this code to change the intersected dynamic text
                                                         c116.text = alphaA[j];
                                                       }
                                                       tl["c"+(120+_root.ctr)].text = alphaA[j];
                                                  }
                                                }
                                              }
                                        }
                                        Key.addListener(kLO);
                                        }

                                        cr2.jpg

                                        its working until i click on the mc number 1 and typed Q, W, E, R:


                                        this is what happen

                                         

                                        cr1.jpg

                                         

                                        this is the code on mc box 1:

                                         

                                        on (release) {
                                        _root.ctr = 0;
                                        y11_mc._alpha = 100;
                                        y12_mc._alpha = 0;
                                        var tl:MovieClip=this
                                        var alphaS:String="abcdefghijklmnopqrstuvwxyz";
                                        var alphaA:Array = alphaS.split("");

                                        var kLO:Object = new Object();
                                        kLO.onKeyDown = function() {
                                            for(var j:Number=0;j<26;j++){
                                                  if (Key.isDown(65+j || 97+j)) {
                                                  _root.ctr++;
                                                  if (_root.ctr < 9) {                                             //number 1 consists of 8 letters
                                                       tl["c"+(110+_root.ctr)].text = alphaA[j];
                                                  }
                                                }
                                              }
                                        }
                                        Key.addListener(kLO);
                                        }

                                         

                                        what could be wrong?? i tried to change the name of the variables like alphaS2, alphaA2....but same outcome....

                                        • 17. Re: crossword problem...
                                          dn0myar06 Level 1

                                          hi kglad!!! i'm still having problems with the codes when it comes to intersection of my puzzle

                                           

                                          i created mc's in the first box of every number and attached the code that you gave me, and added some lines...

                                           

                                          when i click the first mc and type any key, it works fine, but when i click on the 2nd mc there's a gap in assigning letters to my dynamic text field, and the other textfields in the first mc also changes...

                                           

                                          hope you could help...

                                          • 18. Re: crossword problem...
                                            dn0myar06 Level 1

                                            got it...i used Key.removeListener(kLO);