问题
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.
回答1:
It seems like this is a bug limited to the debug player.
Debug version of Flash Player 11.1 reproduces this bug, while the Chrome version 11.2 and browser plugin 11.1 does not.
回答2:
Use a boolean. For example, make it true in the resize function and check if it's not true to execute it.
来源:https://stackoverflow.com/questions/10913432/how-to-prevent-event-resize-to-trigger-twice-on-displaystate-change-to-full-scre