I have an application with an fullscreen button, when that button is clicked I change the displayState of stage to StageDisplayState.FULL_SCREEN_INTERACTIVE
.
That makes Event.RESIZE
fire twice if stage.scaleMode = StageScaleMode.NO_SCALE
.
The event is only fireing once if i change back to stage.displayState = StageDisplayState.NORMAL
.
Anyone know a good way to prevent the Event.RESIZE from fireing twice except calling the onResize function directly or implementing a custom event?
Sample code that reproduces the issue:
package test
{
import flash.display.Sprite;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite
{
public function Main():void
{
if (stage)
this.init();
else
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(Event.RESIZE, onResize);
stage.scaleMode = StageScaleMode.NO_SCALE;
var button:Sprite = new Sprite();
button.mouseEnabled = true;
button.addEventListener(MouseEvent.CLICK, doResize);
button.graphics.lineStyle(3,0x00ff00);
button.graphics.beginFill(0x0000FF);
button.graphics.drawRect(10, 10, 100, 100);
button.graphics.endFill();
this.addChild(button);
}
private function doResize(e:MouseEvent) : void {
if (stage.displayState == StageDisplayState.NORMAL) {
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
else {
stage.displayState = StageDisplayState.NORMAL;
}
}
private function onResize(e:Event) : void {
trace("onResize", stage.displayState);
}
}
}
Further investigation shows that it seems like switching to fullscreen is two steps, first one resize to a StageDisplayState.NORMAL
and then to StageDisplayState.FULL_SCREEN_INTERACTIVE
.