我正在尝试设置全屏切换并实现流畅性元素,但是我不确定是否必须在屏幕调整大小的切换中包含调度事件,或者这将是前一个eventListener将检测到的内容全屏切换是否已激活?
此外,我已经在网上查了几天关于这个主题,我仍然不确定在哪里放置我的舞台元素的调整大小是最佳的。
public function Main():void {
addEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(Event.RESIZE, resizeListener);
stage.addEventListener(FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED, fullScreenRedraw);
}
private function resizeListener (e:Event):void {
// - Do I put my resize control options here to cater for general resize or see below?
myMovie.width = stage.stageWidth; // etc
}
private function fullScreen(e:MouseEvent):void {
try {
switch (stage.displayState) {
case StageDisplayState.FULL_SCREEN_INTERACTIVE:
/* If already in full screen mode, switch to normal mode. */
stage.displayState = StageDisplayState.NORMAL;
break;
default:
stage.fullScreenSourceRect = null;
// If not in full screen mode, switch to full screen mode.
stage.dispatchEvent(new Event(Event.RESIZE));
stage.displayState = StageDisplayState.NORMAL;
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
break;
}
} catch (err:SecurityError) {
// ignore
}
}
private function fullScreenRedraw(event:FullScreenEvent):void {
if ( event.fullScreen ) {
// FULLSCREEN TRUE
// - Or do I put my resize control options here to cater for the fullscreen as well?
myMovie.width = stage.stageWidth; // etc
var fScrField:TextField = new TextField();
fScrField.y = 480;
fScrField.text = "Redraw : True";
addChild(fScrField);
} else {
// NON FULLSCREEN
fScrField.text = "Redraw : False";
addChild(fScrField);
}
}
* * adobe上提到的修改后的处理程序。但是关于什么地方和原因的相互矛盾的信息?!
private function activateHandler(event:Event):void {
trace("activateHandler: " + event);
}
private function fullScreenRedraw(event:FullScreenEvent):void {
if ( event.fullScreen ) {
// Add additional panels if set/sizes
var fScrField:TextField = new TextField();
fScrField.y = 480;
fScrField.text = "Redraw : True";
addChild(fScrField);
} else {
// Remove additional panels etc
fScrField.text = "";
fScrField.text = "Redraw : False";
addChild(fScrField);
}
}
现在我已经能够使用上面的代码以各种方式使用变体,但是花了几天在线谷歌搜索似乎没有效率或明确的解释,这是最好的。
任何可以更好地优化和提高效率的帮助,因为我只是从我可以解决的问题中撬开它。
提前致谢。
答案 0 :(得分:1)
我认为你过于复杂了。试试这个:
// in your constructor:
fullScreenBtn.addEventListener(MouseEvent.CLICK, toggleFullScreen);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, refreshStage);
stage.addEventListener(Event.RESIZE, refreshStage);
// then handle stage resize:
private function refreshStage(event:Event = null):void
{
if ( stage.displayState == StageDisplayState.NORMAL ) {
// handle stage in normal mode
} else {
// handle stage in full screen mode
}
}
// handle stage state toggle:
private function toggleFullScreen(event:Event = null):void
{
if ( stage.displayState == StageDisplayState.NORMAL )
stage.displayState = StageDisplayState.FULL_SCREEN;
else
stage.displayState = StageDisplayState.NORMAL;
}