FlashPlatform Initialization

来自Blueidea
enc0717讨论 | 贡献2011-04-13T22:43:42的版本 舞台尺寸的軟匹配:

跳转至: 导航搜索

Flash platform 應用初始化常用設置。


舞台尺寸的軟匹配:

/*
~~ Blueidea wiki [Category:Flash platform]~~
www.blueidea.com
*/
package {
  import flash.display.Shape;
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;
 
  // ${1}
  /**
   * The <code>Molehill</code> class.<br/>
   */
  public class Test extends Sprite {
    //==========================================================================
    //  Constructor
    //==========================================================================
    /** Constructor */
    public function Test() {
      stage.align = StageAlign.TOP_LEFT;
      stage.scaleMode = StageScaleMode.NO_SCALE;
      // 待會用來填充舞台。
      $shape = new Shape();
      repaintBorder(stage.stageWidth, stage.stageHeight);
      stage.addEventListener(Event.RESIZE, stage_resizeHandler);
    }
    private var $border:Shape;
    private function repaintBorder(width:uint, height:uint):void {
      // ${2}
    }
    //==========================================================================
    //  Event listeners
    //==========================================================================
    private function stage_resizeHandler(event:Event):void {
      repaintBorder(stage.stageWidth, stage.height);
    }
  } // <- end class ->
}

通常我們會對stage做如上設定讓舞台在左上角對齊,並且當FlashPlayer尺寸設置時令縮放保持不變。

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;


接下來對FlashPlayer設定一個初始大小。如果您使用的Flash IDE那麼直接在設置面板設置即可。 如果您使用的時Flash Builder那麼可以在${1}處加入使長寬為900 x 600並指定60fps刷新率。

[SWF(width="900", height="500", frameRate="60")]