简体   繁体   中英

Flash As3 Window resize issue

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);
        }
    }
}

Here is my code

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);
  ...
}

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

if center aligned

btn.x = stage.stageWidth / 2;
btn.y = stage.stageHeight / 2;

if top left

btn.x = stage.stageWidth / 2 - btn.width / 2;
btn.y = stage.stageHeight / 2 - btn.height / 2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM