-
Cannot Delete Arrays
I am currently making a small game using a couple of arrays, which contain MCs.
It goes like this:
Code:
grid = new Array();
for(i=0;i<array_length;i++){
this["row"+i] = new Array();
}
MCs are the added for reference in the "row" arrays.
Where I am having trouble is reseting or deleting these arrays. What I want to do is simply run those few lines again to have empty arrays using the same names. However, running those lines afterwards does nothing.
I tried adding
Code:
delete grid
grid = new Array();
for(i=0;i<array_length;i++){
delete this["row"+i]
this["row"+i] = new Array();
}
or putting things like grid = undefined or another value... but when I use "delete this["row"+i]", the array keeps its elements.
However, if I do the same using "delete row0", it actually gets rid of the array as intended, however the array CANNOT be re-create using "this["row"+i] = new Array();"
The only way I see aroung this problem would be to hard code ever array as
delete row0;
delete row1;
delete row2;
...
and then
row0 = new Array();
row1 = new Array();
...
But that just wrong... there's got to be things I don't understand in this situation... Any hints on what I am doing wrong ?
-
Ok messed around some more and found something I don't understand.
I am calling both the "this[xyz]= new Array()" and "delete this[xyz]" inside and MC, and I traced something for fun...
When I am declaring variables, tracing this._name returns "game", the MC's name... however, when deleting, tracing this._name returns undefined...
So the problem is not about deleting arrays, which works just fine by using _root.game[xyz], but why is "this" returning undefined ?
I used for the first time the "setTimeout" function... could it be that calling a function located inside an MC from a Timeout loses reference to the MC ?
-
Flashmatics
to delete an array you can simply declare it again:
e.g
var someArray:Array = ["a" , "b", "c"];
trace(someArray[0]) // gives "a"
//now to 'delete' the array simply do:
someArray = []; // or you can do someArray.length = 0;
trace(someArray[0]) // traces undefined
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|