Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Getting an Array from a multi-dimentional Array within a Function

New Here ,
Apr 26, 2013 Apr 26, 2013

Don't know how to explain it but here, firstly, I can't get past. Also had this problem with another thing I was trying.

ReferenceError: Error #1056: Cannot create property 0 on Number.

I googled and found out about automatically declare stage instances, that was fine, I had the box checked.

Basically, it is failing at even the simplest. I have this function:

function getInfoOf(i) { // enemy count, info count

    var _info:Array = new Array(3, 6);

    // 0 is you

    _info[0,Const.MAXHP] = 500;

    _info[0,Const.CURRENTHP] = 500;

    _info[0,Const.LEVEL] = 5;

    _info[0,Const.EXP] = 5500;

    _info[0,Const.NAME] = "You";

    _info[0,Const.LINKEDMC] = "NONE";

    // then a few more _info's.

}

Then, trying everything to get it to work, I stripped it so no returns. So in the code, in the init() part of the project (only called once), have getInfoOf(0), and tried any other numbers. I recieve that error, and cannot for the life of me figure out whats wrong (I have also tested the "Const"'s. they are integers, and I have tested using numbers in  place of those. Still same error, it only goes away when I don't call the function at all.

Any help would be greatly appreciated.

Thanks.

Message was edited by: brokenhope The array is actually (3,6), messed that up.

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 26, 2013 Apr 26, 2013

again, to access an array element (eg, the last), use:

_info[2][5]="whatever";

NOT

    info[0,5] = 0;

Translate
Community Expert ,
Apr 26, 2013 Apr 26, 2013

i'm not sure what you're trying to do but, if you're trying to create a 2d (3x6) array, among the ways to do that is:

var _info:Array=new Array(3);

for(var i:int=0;i<_info.length;i++{

_info=new Array(6);

}

then to access an array element (eg, the last), use:

_info[2][5]="whatever";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2013 Apr 26, 2013

I don't know whats wrong here. I tried to get it to work on the project, still same exact error. So, I tried it on a entirely new project, and still get the exact same error. So I also put in a new function to test with no array.

stop();

function getInfoOf2():void {

    var blah = "testwat";

    trace(blah);

    return;

}

function getInfoOf():void {

   

    var info:Array=new Array(3);

    for(var i:int=0; i<info.length; i++) {

        info=new Array(6);

    }   

   

    // 0

    info[0,0] = 500;

    info[0,1] = 500;

    info[0,2] = 5;

    info[0,3] = 5500;

    info[0,4] = 0;

    info[0,5] = 0;

   

    return;

}

this.getInfoOf2();

this.getInfoOf();

the function still fails, but the first function doesn't.

testwat

ReferenceError: Error #1056: Cannot create property 0 on Number.

    at Untitled_fla::MainTimeline/getInfoOf()

    at Untitled_fla::MainTimeline/frame1()

any ideas, I did a few traces, that message appears at the first info[0][0].

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2013 Apr 26, 2013

var theTestRow:Object = getInfo(2);

trace(theTestRow[4]); // 34

function getInfo(i):Object {

    var info:Object = new Object();

    info[0] = [2,4,7,3,8,3];

    info[1] = [23,53,76,32,68,74];

    info[2] = [0,896,45,355,34,35];

    return info;

}

No matter what I tried, could not get a 2 dimensional array to work. I tried 1 dimensional and no problem there. So, either could have done multiplication and a 1 directional array, or this, which works no problem.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2013 Apr 26, 2013

again, to access an array element (eg, the last), use:

_info[2][5]="whatever";

NOT

    info[0,5] = 0;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2013 Apr 27, 2013

My mistake, copy and pasted that bit with the comma when testing.

You're exactly right.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2013 Apr 27, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines