Skip navigation
Currently Being Moderated

Nested Arrays: Syntex help needed

Aug 21, 2013 4:31 PM

In my spelling game I have Levels of 10 words in each level and each word has to be broken up into its phonetic sounds. Because I'm working with phonetic sounds, I can not simply split the word up into letters - so I had to do each word manually according to its sounds (not individual letters).

 

Here are the first five words of level 1, each split as I want it:

 

public var  wordsL1W1:Array = ["e","l',"e","ph","a","nt" ];

public var  wordsL1W2:Array = ["h","a","s"];

public var  wordsL1W3:Array = ["o","f"];

public var  wordsL1W4:Array = ["o","ff"];

public var  wordsL1W5:Array = ["o","n"];

 

I would like to add them all to a nested array (named wordsL1) so that I can manipulate the array as a whole e.g. loops and things. Here is how I wrote it:

 

public var  wordsL1:Array = [wordsL1W1,wordsL1W2,wordsL1W3,wordsL1W4,wordsL1W5];

 

And when I trace it like below I expect the following in the output box: e,l,e,ph,a,nt

 

     trace(wordsL1[0]);

 

BUT I get //null in the output pannel

 

What did I do wrong?

 

Thanks

Charine

 
Replies
  • Currently Being Moderated
    Aug 21, 2013 4:43 PM   in reply to Charine -FB buggoop

    For the code that you show, what you expect to get is what you should get, so what you might have done wrong might lie in something you are not showing.  You might need to show more of what's involved with how you arrange this code in the class file... maybe you are calling the trace before you've defined the Arrays?

     

    Have you tried tracing wordsL1 itself to see if it indicates it is an Array?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2013 9:36 AM   in reply to Charine -FB buggoop

    You're assigning an array full of objects you haven't even created yet. The compiler creates them in the order in which you write.

     

    Simply move this line below all the defined variables it uses. e.g.:

     

    package

    {

           import flash.display.Sprite;

     

           public class classarray extends Sprite

           {

                 public var  wordsL1W1:Array = ["e","l","e","ph","a","nt"];

                 public var  wordsL1W2:Array = ["h","a","s"];

                 public var  wordsL1W3:Array = ["o","f"];

                 public var  wordsL1W4:Array = ["o","f","f"];

                 public var  wordsL1W5:Array = ["o","n"];

                 public var  wordsL1W6:Array = ["n","o","t"];

                 public var  wordsL1W7:Array = ["g","o","t"];

                 public var  wordsL1W8:Array = ["i","n"];

                 public var  wordsL1W9:Array = ["i","s"];

                 public var  wordsL1W10:Array = ["i","t"];

     

                 // now that all vars are defined/exist

                 public var  wordsL1:Array = [wordsL1W1,wordsL1W2,wordsL1W3,wordsL1W4,wordsL1W5,wordsL1W6,wordsL1W 7,wordsL1W8,wordsL1W9,wordsL1W10];

     

                public function classarray()

                {

                        trace(wordsL1[0]);

                }

         }

    }

     

    Traces:

     

    e,l,e,ph,a,nt

    [SWF] classarray.swf - 2,083 bytes after decompression

    [Unload SWF] classarray.swf

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2013 10:42 AM   in reply to Charine -FB buggoop

    Some look ahead compilers would fix this issue for you but in this case we all learn something new every day . You're welcome and good luck!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points