Say I have populated the array/page with clone items, and want to trash them all, the following code would do just that
Code:
for (loop=0;loop<myTextClones.length;loop++)
{
myTextClones[loop].DestroyClonedObject()
}
Debug.trace("Array length: "+ myTextClones.length +"\n")
The debug statement at the end confirms that the array item still contains the information of the objects.
you can delete an item "using" the array index, again the array here remains the same...
Code:
myTextClones[2].DestroyClonedObject()
delete item three...
I am assuming now that you simply want to eliminate a couple of the clone objects and want to cleanup the array object.
I salvaged this bit of code from one item I got help with by someone in the forum, and after trawling through a real gem of ECMAScript document
http://www.ecma-international.org/publi ... ma-262.pdf, another good resource is
http://phrogz.net/ObjJob/object.asp?id=314 just about understood the workings of the code but here goes...
You need to create the following function in a script object (keep the comments please...)
Code:
/*--------------------------------------------------------------
Array Functions
-The splice() method BOTH removes and inserts elements based
on the parameters you feed it.
-The first parameter is an index number of the element list
indicating where to start.
-The second parameter tells the function how many elements of
the array to remove starting at the indexed element.
-The remaining parameters are elements to add to the array after
its indexed element.
---------------------------------------------------------------*/
function Array_splice(index, delTotal) {
var temp = new Array()
var response = new Array()
var A_s = 0
for (A_s = 0; A_s < index; A_s++) {
temp[temp.length] = this[A_s]
}
for (A_s = 2; A_s < arguments.length; A_s++) {
temp[temp.length] = arguments[A_s]
}
for (A_s = index + delTotal; A_s < this.length; A_s++) {
temp[temp.length] = this[A_s]
}
for (A_s = 0; A_s < delTotal; A_s++) {
response[A_s] = this[index + A_s]
}
this.length = 0
for (A_s = 0; A_s < temp.length; A_s++) {
this[this.length] = temp[A_s]
}
return response
}
if (typeof Array.prototype.splice == "undefined") {
Array.prototype.splice = Array_splice
}
//Syntax
// arrayObj=new Array(1,2,3,4,5,6,7,8,9,0)
// var x = arrayObj.splice(startIndex, cutTotal , arg0 , arg1,...)
// var x = arrayObj.splice(2,3,10,11,12)
// starting at index 2, deal with 3, replace with 10,11,12
And how to use the function
Code:
myTextClones.splice(1,1)
here, I am telling the code to start from index1 and delete 1 item. hence the first 1 can be a variable holding the index of the object you deleting from the array, and second one will remain as one... the array object lenth will reduce by 1....
again will like to thank forum member who originally posted the piece of code, see I remembered how it was to be used... ...