16 October 2007

Actionscript 3.0 — Full-screen Centered Flash

By: Michael Boucher

I converted an AS2 script I found for positioning full-screen, centered flash web sites to AS3. Couple of things changed and there was one instance where I got stumped because of syntax/function differences.

This stemmed from a thread over on Ultrashock.com. The thread is a great resource is if you looking to do any sort of full-screen and/or centered flash web sites. Thread also covers tiled backgrounds in Flash 8.

Note that this file is saved as CenterAlign.as and set as the Document Class in your Flash CS3 FLA file.

Shout goes to Nutrox at Ultrashock.com for the lesson in Bitwise Operators.

 
package
{     
 
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;    
 
  import InterfaceContainer;     
 
  public class CenterAlign extends Sprite
  {     
 
    public var XI:InterfaceContainer;     
 
    public function CenterAlign()
    {     
 
      // --------- Set Stage Properties ----------     
 
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;     
 
      // --------- Listen for Stage Resize -------
      stage.addEventListener(Event.RESIZE,RepositionInterface);     
 
      XI = new InterfaceContainer();
      addChild(XI);     
 
      RepositionInterface();     
 
    }     
 
    // Aligns Interface to Center of Stage
    public function RepositionInterface(e:Event=null):void
    {     
 
      var newX = (stage.stageWidth - XI.width) >> 1;
      var newY = (stage.stageHeight - XI.height) >> 1;
      XI.x = newX;
      XI.y = newY;     
 
    }     
 
  }     
 
}

Filed under: Adobe Flash, Actionscript 3.0 — Michael Boucher @ 12:43 am

Article has been tagged:

, , , , , , , , ,

1 Comment »

  1. Pingback by MINDTWITCH Blog » Actionscript 3 Code Highlighting with GerSHi — 16 October 2007 @ 12:59 am

    […] ready for download soon. You can see an example of it in action on this site. Just check out the Actionscript 3.0 — Full-screen Centered Flash post. Filed under: Adobe Flash, PHP, Actionscript 3.0, Side Projects, WordPress — mindtwitch […]

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.