Previous Page
Next Page

Recipe 3.7. Changing the Alignment

Problem

You want to change the alignment of the movie within the Player.

Solution

Use the stage.align property.

Discussion

Flash movies appear in the center of the Player by default. You can control the alignment of a movie within the Player by setting the stage.align property of any class that extends DisplayObject. The various alignment modes are implemented as strings, such as "T" for "top," "L" for "left," etc. However, to avoid errors in typing, these have also been made properties of the flash.display.StageAlign class, listed in Table 3-1.

Table 3-1. Alignment as controlled by stage.align
Value Vertical alignment Horizontal
StageAlign.TOP 

Top Center
StageAlign.BOTTOM 

Bottom Center
StageAlign.LEFT 

Center Left
StageAlign.RIGHT 

Center Right
StageAlign.TOP_LEFT 

Top Left
StageAlign.TOP_RIGHT 

Top Right
StageAlign.BOTTOM_LEFT 

Bottom Left
StageAlign.BOTTOM_RIGHT 

Bottom Right

There is no "official" value to center the Stage both vertically and horizontally in the Player. Of course, if this is what you want, you don't have to do anything since that is the default mode. But if you have changed to one of the other modes and want to go back to centered alignment, any string that doesn't match one of the other modes will center the Stage. The easiest and safest would be an empty string, "".


The following class demonstrates the effects of both the scale mode and alignment of a movie within the player. Experiment by changing the stage.scaleMode and stage.align properties to their different values and scaling the browser to various sizes.

package {
  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;

  public class ExampleApplication extends Sprite {
    public function ExampleApplication(  ) {

      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_RIGHT;
      
      graphics.beginFill(0xff0000);
      graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
      graphics.endFill(  );
    }
  }
}


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)