...

View Full Version : Resolved: Array assignment error in AS2 - Simple bug



udjamaflip
07-29-2009, 10:50 AM
Hi guys,

Here is the piece of code which doesn't seem to work:



lang_array[i]['eng'] = english;
lang_array[i]['pol'] = polski;
lang_array[i]['de'] = deutsch;
trace(english);
trace(i);
trace(lang_array[i]['eng']);


the trace from this (it loops through 3 times)



This is a transcript..
0
undefined
This is a transcript2..
1
undefined
This is a transcript3..
2
undefined


further up in the code is this:


//added in to support multilingual transcripts
var lang_array:Array = [];


Any ideas why this is failing and the final trace doesn't output anything? I'm fairly new to AS so if you need more than what i've given let me know.

hope someone can help! :thumbsup:

gnomeontherun
07-29-2009, 10:35 PM
Assuming that english polski und deutsch are variables with data associated with them, that shouldn't be the problem. I feel like multidimensional arrays like their keys to be index with numbers, have you tried this?


lang_array[i][0] = 'english';
lang_array[i][1] = 'polski';
lang_array[i][2] = 'deutsch';
trace(english);
trace(i);
trace(lang_array[i][0]);


Also it might make more sense to establish your array like this


//added in to support multilingual transcripts
var lang_array:Array = new Array();

There are several ways to setup your arrays, depending on how you want to store the data.

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000091.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum