12 Replies Latest reply: Jun 26, 2013 5:09 AM by kglad RSS

    Putting Arrays to work: error 1065

    Charine -FB buggoop Community Member

      Hi all,

       

      I have created this array which works well:

       

      function initLetters():void

              {                               

                  for (var i:Number =0; i < lettersL1.length; i++)

                  {

                      trace (lettersL1[i]); // traces perfectly

       

                   }

       

      My next question: I want to do a lot of stuff with the objects in this array, (like suffle, appear at a certain x,y coordinate, change alpha, move along a path etc. All of wich I need to learn yet LOL)

                                   Someone suggested that I add the following code to create a var to do this. When I add this I get the error code below. Is this the righ way to go for what I want?  Maybe it is in the wrong spot again?

       

         /*var C:Class=Class(getDefinitionByName(lettersL1[i]));

                  var c:*=new C(); // create instances from the classes in lettersL1

                                              // do whatever with c*/

       

      When I uncomment the above I suddenly get this error code:

       

      ReferenceError: Error #1065: Variable [object A] is not defined.

          at global/flash.utils::getDefinitionByName()

          at LetterArray/initLetters()

          at LetterArray()

          at BugGoopFSGame()

       

      My .as class code:

       

      package

      {

          import flash.display.*;

          import flash.events.*;

          import flash.text.*;

          import flash.utils.Timer;

          import flash.utils.getDefinitionByName;

          import flash.media.Sound;

          import flash.media.SoundChannel;

          import flash.net.URLRequest;

       

       

          public class LetterArray extends MovieClip

          {

              private var _stage:Stage;

       

              //Movie clips to be used

              public var a:A = new A();//etc

       

              private var  lettersL1:Array = [a,f,g,h,i,n,o,s,t];

       

              //Text Fields and Format

                                                                  //works well

                                                            //Sound Specs

                                                                  //works well

       

              //***CONSTRUCTOR FUNCTION***

       

       

              public function LetterArray(s:Stage)

       

              {

                  _stage = stage;

       

                  trace("Main construtor is working");

       

                  //GameLoop

                  initText();

                  initLetters();

                  initLetterWasClickedOn();

                  initCheckIfLetterIsCorrect();

                  initInGameAnimation();

                  initRemoveLetterChildren();

                  initPointsGiven();

              }

       

          //OTHER FUNCTIONS

       

              function initText():void

                      {                               

                          // text formatting: general

                       }

       

              function initLetters():void

              {                               

                  for (var i:Number =0; i < lettersL1.length; i++)

                  {

                      trace (lettersL1[i]); //trace works well

       

                  var C:Class=Class(getDefinitionByName(lettersL1[i]));

                  var c:*=new C(); // create instances from the classes in lettersL1

                                              // do whatever with c

                  }

        • 1. Re: Putting Arrays to work: error 1065
          kglad MVP

          do you have classes that match the contents of your array?

          • 2. Re: Putting Arrays to work: error 1065
            Charine -FB buggoop Community Member

            Hi kglad,

            Nice to hear from you again.

             

            Yes I do have classes that match the contents. They are little images that I converted to movieclips (and let flash make classes for me) and when I do trace (lettersL1[i]); I see them all listed in my output pannel like this:

                          

                           [object A]

                           [object F]

                           [object G]

                           [object H]

                           [object I]

                           [object N]

                           [object O]

                           [object S]

                           [object T]

             

            It is just when I want to add this next step (which you kindly gave me before),

                                                                     var C:Class=Class(getDefinitionByName(lettersL1[i]));

                        var c:*=new C(); // create instances from the classes in lettersL1

                                                    // do whatever with c

            that I get the error message.

             

            I also tried to specify their x and y values using this:

             

                           function initLetters():void

                                   {                               

                                       for (var i:Number =0; i < lettersL1.length; i++)

                                       {

                                           trace (lettersL1[i]);

                                          

                                           letterL1[i].x = 300;             //line 92

                                           letterL1[i].y = 30;              //line 93

                                           letterL1[i].alpha = 0.1;      //line94

                           

                        }

             

            but then Iget this error, for all three lines:

            C:\Users\Charine\Creative Cloud Files\BugGoopFS\Classes\LetterArray.as, Line 92

            1120: Access of undefined property letterL1.

             

            How do I specify behaviour and add these movie clips to my game?

            • 3. Re: Putting Arrays to work: error 1065
              Charine -FB buggoop Community Member

              Please see reply below kglad,

               

              Any other suggestions?

               

              Appreciate your help

              Charine

              • 4. Re: Putting Arrays to work: error 1065
                kglad MVP

                if tracing lettersL1 does not yield strings (like "A","F",etc), you're not using getDefinitionByName correctly.

                 

                in particular, if tracing lettersL1 yields a list of objects, you don't have strings in lettersL1.

                 

                if that doesn't solve the problem for you, copy and paste lettersL1.

                • 5. Re: Putting Arrays to work: error 1065
                  Charine -FB buggoop Community Member

                  Hi kglad,

                   

                  Not sure I understand.

                   

                  My game (for kids) is supposed to have a word at the bottom and then letter tiles appear and move from the top down. The player will click on the letters that correspont to the ones in the word below. I've attached a screenshot with lettertile A [object A] showing.

                   

                  The objects is lettersL1 are all letter tiles to be clicked on. I saved them as movie clips and generated .as files for each. The array I'm making is an array of movie clips (gifs).

                   

                  I think they are tracing correctly  -[object A],[object F],[object G] and so on.

                   

                  Now I would like to code something like - take array named lettersL1 and add a position, an alpha, a path etc. How do I start with one of those properties? Sorry this is very basic, but I think if I know how to do one, I'll be able to figure out the rest.

                   

                  Thanks for your help

                  Charine

                  screenshot.jpg

                  • 6. Re: Putting Arrays to work: error 1065
                    kglad MVP

                    then use:

                     

                    lettersL1[i].x =

                    lettersL1[i].y=

                    lettersL1[i].alpha=

                    // i have no idea how you want to implement a path or even what you mean.

                    • 7. Re: Putting Arrays to work: error 1065
                      Charine -FB buggoop Community Member

                      Hi kglad,

                      Thanks! The above helps me a lot. I left out the - [i] - bit and without that I got error messages of cause. I appreciate you pacience and help with this. Next time I'll know.

                       

                       

                      My next question:

                      So my .as class file called LetterArray looks correct now (with the above added successfully) but I do not see the movie clips appear in the swf yet. I know I must add it to my main .as file. I thought I did that when adding your code

                       

                      to the LetterArray class:

                       

                                                              public class LetterArray extends MovieClip

                          {

                              private var _stage:Stage;

                       

                       

                      and to my main class:

                                                   

                                                         public var letterArray:LetterArray = new LetterArray(stage);

                       

                      I do not know if I must also do an addChild for this in my main class. Here are all the files if you need to take a look: (https://www.dropbox.com/sh/jp8zjemi2dchs51/vke2h7tqxW)

                       

                       

                      By path I ment something like the code below, using a timer

                       

                      public function moveletterL1():void

                              {

                                 lettersL1[i].x = x + 3;

                                 lettersL1[i].y = y + 4;

                              }

                       

                      I tested it out with one letter tile in the swf file here: (https://www.dropbox.com/sh/jp8zjemi2dchs51/vke2h7tqxW)

                      • 8. Re: Putting Arrays to work: error 1065
                        kglad MVP

                        if you have classes a,b,c,d defined and

                         

                        var lettersL1:Array=[a,b,c,d,...];

                         

                        you could use:

                         

                         

                                function initLetters():void

                                {           

                        var prevX:int=0;                   

                                    for (var i:Number =0; i < lettersL1.length; i++)

                                    {                   

                        var letter:*=new lettersSl1[i]();

                        letter.x = prevX;

                        prevX+=letter.width+5;

                        _stage.addChild(letter);

                        }

                        }

                        • 9. Re: Putting Arrays to work: error 1065
                          Charine -FB buggoop Community Member

                          Thanks kglad,

                          I'll use your code when I add a motion path to these.

                           

                          At the moment I am still having problems for them just to appear on stage.

                          This is where the first array (letterTiles for level one) of my .as class for the game loop appears. I think this is correct after your advice:

                           

                               public function initLetters():void

                                  {  for (var i: Number  =0; i < lettersL1.length; i++)

                                      { trace (lettersL1[i]);

                                         lettersL1[i].x = 300;

                                         lettersL1[i].y= 30;

                                                  }

                                      trace("Initiation started");

                                  }

                           

                          Next, I think I should call up this function in my main class. What I did below is incorrect. I had two error 1120 codes saying letterTile was not defined.(I marked it in bold) How do I fix it? Or is there a better way of doing this?

                           

                          Thanks for your help.

                           

                          *****Main .as file******

                          package

                          {

                              import //all

                              public class BugGoopFSGame extends MovieClip

                              {

                                  public var mybackground:BackGround; //and other vars not applicable to my question

                                  public var letterArray:LetterArray = new LetterArray(stage);

                                 public var gameTimer:Timer;

                                

                           

                                  public function BugGoopFSGame()

                                  {

                                      //addChild for stuff not applicable to this question

                                      //Error 1120: Access of undefined property letterTile

                                      /*letterTile = new lettersL1[i]();

                                      _stage.addChild(letterTile);*/

                                       gameTimer = new Timer(31,5120);

                           

                                      //Add event listener for timer;

                                   gameTimer.addEventListener(TimerEvent.TIMER, tickTock); // and others not applicable to this question

                                   gameTimer.addEventListener(TimerEvent.TIMER, initLetters);

                                              }

                           

                                  //Start timer function

                                  public function startTimer(timerEvent:MouseEvent):void

                                  {

                                      gameTimer.start();

                                      trace("Timer started");

                                      myplaybtn.visible = false;

                                  }

                                  //***Start the game

                                 

                                  //Error 1120: Access of undefined property letterTile

                                  /*public function initLetters(timerEvent:TimerEvent):void

                                  {

                                      letterTile.initLetters();

                                  }*/

                                 

                                

                              }

                          }

                          I can post my complete files if you need to see them.                  

                          • 10. Re: Putting Arrays to work: error 1065
                            kglad MVP

                            does lettersL1 look like message 8?

                             

                            if yes, use that code to create objects.  if no, show lettersL1

                            • 11. Re: Putting Arrays to work: error 1065
                              Charine -FB buggoop Community Member

                              Hi kglad,

                              Thank you so much for your pacience. At last I can see my letter tiles on the stage. Now I can start adding more functionality.

                               

                              I really appreciate you help

                              • 12. Re: Putting Arrays to work: error 1065
                                kglad MVP

                                you're welcome.