Keith, isn't the issue here more that the timer and stage references remain?
That is, that weak references only free up an object for later collection if
there is no other reference, but aren't the same as removing a listener?
For the running timer to be the issue, wouldn't the timer reference have to
be nullified prior to the 10th trace?
The code at the end of this email is a hastily adapted example (best
practices not assured) that I think illustrates the timer-running issue. If
the third line of the onTimer() method remains commented, all ten traces
occur even after the timer object is nullified, illustrating Arno's
description. If the line is uncommented, the trace ceases after four
occurrences, as expected, because the timer was stopped first.
In the original example, however, isn't the fact that the trace occurs 10
times, and the click remains active, due to the fact that the references
remain?
Rich
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.*;
public class TestDic extends Sprite {
public var timer:Timer;
private var n:int = 0;
private var h:Handler;
public function TestDic() {
timer = new Timer(50, 10);
timer.addEventListener(TimerEvent.TIMER, onTimer,
false, 0, true);
timer.start();
h = new Handler(this);
h.name = "Test handler: ";
stage.addEventListener(MouseEvent.CLICK, h.handler,
false, 0, true);
}
private function onTimer(e:*):void {
trace(n);
if (n >= 3) {
//timer.stop();
timer = null;
h._timr = null;
}
trace(h.name);
n++;
}
}
}
class Handler {
import flash.utils.Timer;
import flash.events.MouseEvent;
public var name:String;
public var _timr:Timer;
public function Handler(p:*) {
_timr = p.timer;
}
public function handler(e:MouseEvent):void {
trace(e);
if (_timr != null) {
_timr.start();
}
}
}
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org