arraysactionscript-3flashactionscriptflash-cs5.5

If I have a multidimentional array, how can I acsess only the first value of the first dimention?


If I have a multidimentional array, how can I acsess only the first value of the first dimention. I will Explain:

sampleArray=new Array[];

sampleArray[0]=["Nouns","Adjectives","Verbs"];
sampleArray[1]=["Colors","Time","Sound];
sampleArray[0][0]=["Person","Place","Thing"]

I would just like to get the word Nouns but when I try to get the value ofsampleArray[0][0] it will just result Person, Place, Thing!


Solution

  • In your sample code "Nouns" is actually located at

    sampleArray[0][0]
    

    However you are replacing that with

    sampleArray[0][0]=["Person","Place","Thing"]
    

    Perhaps it would be easier to keep your information in an object. Then reference them that way. Not sure what your end goal is though so that may not work for you.

    var partsOfSpeach = {};
    var noun = {};
    noun.name = "Noun";
    noun.def = ["Person","Place","Thing"];
    partsOfSpeach.Noun = noun;
    

    Then you can access the info at

    trace(partsOfSpeach.Noun.name); // "Noun"
    trace(partsOfSpeach.Noun.def); // "Person","Place","Thing"