user1212216
user1212216

Reputation: 41

Error with 2D array - Error #1010: A term is undefined and has no properties

The first 2 loops set the textfields just fine. But the next 2 give me the error Error #1010: A term is undefined and has no properties. Something is NULL, but what? Can't figure out :(

import flash.text.TextField;

var suallar:Array = new Array();
var cavablar_temp:Array = new Array();

var i:int;
var j:int;

suallar.push(["sual1", "duz1", "sehv11", "sevh12", "sevh13","sevh14"]);
suallar.push(["sual2", "duz2", "sehv21", "sevh22","sevh23","sevh24" ]);
suallar.push(["sual3", "duz3", "sehv31", "sevh32","sevh33","sevh34"]);
suallar.push(["sual4", "duz4", "sehv41", "sevh42","sevh43","sevh44"]);
suallar.push(["sual5", "duz5", "sehv51", "sevh52","sevh53","sevh54"]);

var sualYeri:Array = new Array();
for (i=0; i<suallar.length; i++)
{
    sualYeri[i] = new TextField();
}




for (i=0; i<suallar.length; i++)
{
    sualYeri[i].text = suallar[i][0];

    sualYeri[i].x = 0;
    sualYeri[i].y = 50 * i;
    addChild(sualYeri[i]);
}

trace(sualYeri.join("\n"));
trace(suallar.join("\n"));

last 2 loops, that don't work start here

var cavabYeri:Array = new Array();

for (i=0; i<suallar.length; i++)
{
    for (j=0; j<suallar.length; j++)
    {
        cavabYeri[i][j] = new TextField();

    }
}
trace(cavabYeri.join("\n"));



for (i=0; i<suallar.length; i++)
{
    for (j=0; j<suallar[i].length; j++)
    {
        cavabYeri[i][j].text = suallar[i][j];

        cavabYeri[i][j].x = 0 + 100 * j;
        cavabYeri[i][j].y = 0 + 100 * i;
        addChild(cavabYeri[i][j]);
    }

}

Upvotes: 0

Views: 1193

Answers (2)

Marty
Marty

Reputation: 39456

You're having the exact same problem as what exists in this question that I've answered.

You can't immediately assign values to array[i][j] without first creating an array at array[i].

Upvotes: 2

sch
sch

Reputation: 27506

The problem is that you initialized the cavabYeri array but not its subarrays.

for (i=0; i<suallar.length; i++)
{
    cavabYeri[i] = []; // or new Array();
    for (j=0; j<suallar.length; j++)
    {
        cavabYeri[i][j] = new TextField();
    }
}

Upvotes: 2

Related Questions