This one is really confusing me. I’m dispatching an IndexChangedEvent that I’ve created myself, setting the oldIndex and newIndex properties before dispatching. When the event is received in the appropriate handler, the oldIndex and newIndex values are received as -1, even though I’ve verified them (using Alert.show()) to be the correct value before being sent.
I’m creating it like this:
var myEvent:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.HEADER_SHIFT, false, false, null, 3, 2);
The 3,2 parameters are just ones that I’m using for debugging, and they should (and I’ve verified that they do) set the oldIndex and newIndex properties of the IndexChangedEvent. I then immediately dispatch the event like so:
dispatchEvent(myEvent);
The handler is set up as follows:
report.addEventListener(IndexChangedEvent.HEADER_SHIFT, shiftHandler);
And here is the handler code:
private function shiftHandler(event:IndexChangedEvent):void {
if (event.oldIndex == -1 || event.newIndex == -1) {
Alert.show("-1 index received");
}
}
To help ensure that I am not crazy, this is my ACTUAL code before dispatching the event:
var myEvent:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.HEADER_SHIFT, false, false, null, 3, 2);
Alert.show(myEvent.oldIndex + " : " + myEvent.newIndex);
dispatchEvent(myEvent);
Every time I shift a header (which fires the event), I get 2 Alert boxes, one that shows 3 : 2 and another that shows -1 index received. It’s driving me crazy. Can someone let me know why my event’s properties aren’t being persisted across a dispatch?
Just a hunch, but it sounds to me as if you’re dispatching the
IndexChangedEventfrom somewhere else, perhaps another listener in your code. If you have a look at the documentation for the event, the default values for theoldIndexandnewIndexproperties are both -1 so something like the following would result in the erroneous event you receive:Have you tried searching your code base for references to
IndexChangedEvent.HEADER_SHIFT?