Hi.
I'm working on a fairly complex program in which I am manipulating arrays in several ways including, changing the position of elements in the array, adding items to the array and deleteing items from the array.
I am tracing the array after each manipulation to see if the correct values are reported and noticed a weird problem.
When adding to the array (which is triggered by a drag and drop) I get the correct initial value and the correct value after the value is added, in other words I see the new value in the array in the correct position. For example "C042.jpg" is the value added and that is what is traced.
after rebuild and showArray = C001.jpg,C042.jpg,C002.jpg, . . .
However, when I trace the array from another function, the added element no longer appears. So for example if I check the array prior to deleting, I get the following:
prior to delete and show array = C001.jpg,C002.jpg,C003.jpg, . . .
The array has reverted to it's initial state.
I'd appreciate any Ideas you may have.
Best regards,
Chris McLaughlin
Hi,
Thanks for your reply. When I simplify the code it works perfectly.
var showArray:Array = new Array("1", "2", "3", "4");
add_btn.addEventListener(MouseEvent.CLICK, addToArray)
delete_btn.addEventListener(MouseEvent.CLICK, delFromArray)
function addToArray(event:MouseEvent):void {
trace("prior to add and the showArray = " + showArray);
showArray.unshift("x");
trace("after add and the showArray = " + showArray);
}
function delFromArray(event:MouseEvent):void {
trace("prior to delete and the showArray = " + showArray);
showArray.splice(0, 1);
trace("after del and the showArray = " + showArray);
}
So that led me to thinking.
When problems like these arise the culprit is usually that the trace is occurring before all the scripts that could affect it have run their course. That one never fails to bite me on the buttocks.
So I looked above and sure enough I saw that there was a script in which I was removing an index showArray.splice(dragIndex, 1) that was executing both when an index was added and when an index was moved as opposed to just when an index was moved. Yikes.
Thanks for helping me think.
CS
North America
Europe, Middle East and Africa
Asia Pacific