Use Splice to delete all elements in an Array
4 December 2008
No Comment
In my project i was passing array to another class(passing by reference). And i was editing the items there in another class(Composition). I was in a situation to resset the array. Then i suddenly reinitialized the array(arr = new Array() or arr = []).
That will create some error in application. Bcoz the reference will end there.
So its advisable to delete items alone. When passing the array references accross several Class.
var Num_arr:Array = new Array();
Num_arr.push(1)
Num_arr.push(6)
Num_arr.push(2)
Num_arr.push(4)
Num_arr.push(9)
trace("--"+Num_arr+"--")
arr.splice(0,Num_arr.length)
trace("--"+Num_arr+"--")
Happy coding
Translate this post











































Leave your response!