2.6. 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, as shown in Table 2-1.

Table 2-1. Alignment as controlled by Stage.align

Value

Horizontal alignment

Vertical alignment

“T”

Center

Top

“B”

Center

Bottom

“L”

Left

Center

“R”

Right

Center

“C” or " "

Center

Center

“LT” or “TL”

Left

Top

“RT” or “TR”

Right

Top

“LB” or “BL”

Left

Bottom

“RB” or “BR”

Right

Bottom

Tip

There is no “official” value to center the Stage both vertically and horizontally in the Player. Technically, any string that doesn’t match one of the other modes will center the Stage. The value “C” is listed in Table 2-1 because it is convenient to remember and it will work.

The following code demonstrates the effects of both the scale mode and alignment of a movie within the Player. This code relies on the DrawingMethods.as file from Chapter 4 (specifically, the drawRectangle( ) method). Additionally, make sure to include the PushButton component in the movie’s Library (see Recipe 11.1). Once you have added this code to a new movie’s main timeline, test the movie in the Standalone Player. Experiment by scaling the Player and clicking on the different buttons to see the effects.

// Include DrawingMethods.as from Chapter 4 for the drawRectangle(  ) method. ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.