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.Se开发者_JAVA技巧curity;
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;
精彩评论