闪存AS3窗口大小调整问题闪存、大小、窗口、问题

2023-09-09 21:31:51 作者:满腔热血

喜 我有一个闪光的脚本,我增加了通过的addChild一招夹,我的电影面积为500x400 与影片剪辑我对准中心。但是,当我试图在浏览器中的不对齐中心设置大小。我所有的计算都得到错误的。

hi I have a flash script, i added one move clip via addChild, my movie area is 500x400 and the movieClip i aligned to center. But when am trying to set the size with in browser its not aligned to center. all my calculations are getting wrong.

package {
    import flash.display.*;
    import flash.display.Stage;
    import flash.geom.*;
    import flash.net.*;
    import flash.media.*;
    import flash.utils.Timer;
    import fl.motion.Color;
    import flash.events.*;
    import flash.text.*;
    import flash.system.LoaderContext;
    import flash.system.Security;

    public class main extends Sprite {

        public function main(){
            trace("Hello");


            var btn:_Button = new _Button();
            btn.x= (stage.stageWidth - btn.width)/2
            btn.y= (stage.stageHeight - btn.height)/2
            addChild(btn);
        }
    }
}

下面是我的code

推荐答案

您需要添加侦听resizeEvent和全屏事件

You need at add listeners to resizeEvent and FullScreen Events.

public function main():void {
  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;
  ...
  ...
  stage.addEventListener(Event.RESIZE, resizeHandler);
  stage.addEventListener(FullScreenEvent.FULL_SCREEN, resizeHandler);
  ...
}

私有函数resizeHandler(五:事件):无效{   btn.x =(stage.stageWidth - btn.width)/ 2   btn.y =(stage.stageHeight - btn.height)/ 2 }

private function resizeHandler(e:Event):void { btn.x= (stage.stageWidth - btn.width)/2 btn.y= (stage.stageHeight - btn.height)/2 }