Ok, this is a Colin Mook source from his oreilly book. It doesn’t work.
The reason is that the stage object is null.
But the book says:
“Notice that within the resizeListener( ) function, stage is directly accessible, just as it is within the ResizeMonitor constructor method.
When an event listener is an instance method, it retains full access to
the methods and variables of its instance.”
Any idea?
package src{
import flash.display.*;
import flash.net.*;
import flash.events.*;
public class ResizeMonitorTest extends Sprite {
public function ResizeMonitorTest ( ) {
// Use "no-scale" mode. (Otherwise, the content
// scales automatically when the application window is resized, and
// no Event.RESIZE events are dispatched.)
stage.scaleMode = StageScaleMode.NO_SCALE;
// Register resizeListener( ) with the Stage instance for
// Event.RESIZE events.
stage.addEventListener(Event.RESIZE, resizeListener);
}
// Define the event listener, executed whenever the Flash runtime
// dispatches the Event.RESIZE event
private function resizeListener (e:Event):void {
trace("The application window changed size!");
// Output the new Stage dimensions to the debugging console
trace("New width: " + stage.stageWidth);
trace("New height: " + stage.stageHeight);
}
}
}