in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Flash MX action script bible - Reinhardt R.

Reinhardt R. Flash MX action script bible - Wiley & sons , 2004. - 987 p.
ISBN: 0-7645-4354-7
Download (direct link): macractionscriptbiblefeb2004.pdf
Previous << 1 .. 241 242 243 244 245 246 < 247 > 248 249 250 251 252 253 .. 427 >> Next

Part V ♦ The Movie Classes
Complete the following steps using the stageWH_101.fla document created earlier in this chapter:
1. Nest the Button component instances and the tOutput text field on the stage into a new Movie Clip symbol named menuClip. Do not include the ComboBox instance. To do this, select the Button i nstances and the text field with the Selection tool (Shift-clicking to select multiple items at once). Press the F8 key to convert the items to a symbol. In the Convert to Symbol dialog box, name the symbol menu, choose the Movie Clip behavior, and click the top-left corner in the Registration icon (see Figure 20-6).
Convert to Symbol 0

iilame: menuClp 1 <* ]
Behavior: @ Movie dip O Button O Graphic Regstrabon: goo □□□ | Cancel | T Advanced ]
Figure 20-6: The Convert to Symbol dialog box
2. Select the new instance of the menuClip symbol on the stage, and assign the instance name of mcMenu i n the Property inspector. Rename the buttons layer mcMenu, and delete the now empty text field layer.
3. Select frame 1 of the actions layer, and open the Actions panel. Select all of the code in the Script pane and copy it (Ctrl+C or ^+C). Then remove all of the code from the Script pane except for the following lines:
this.changeAlign = function(oEvent:Object):Void { var sLabel:String =;
Stage.align = sLabel;
var aAlign:Array = ["L","R","T","B","LT","LB","RT","RB","CC"];
ccbAlign.dataProvider = aAlign;
ccbAlign.addEventListener("change", this.changeAlign);
4. Double-click the mcMenu i nstance on the stage. In this symbol’s timeline, rename Layer
1 objects.
5. While within the timeline of the menuClip (mcMenu) symbol, create a new layer named actions. Select frame 1 of this layer and open the Actions panel (F9). In the Script pane, paste the code you copied in Step 3. Modify the code to reflect the bold code changes shown in Listing 20-3.
In the section of code commented as Code Block #1, most of the changes to the existing changeScale() method are minor. The primary change is that the method resets the position of the mcMenu i nstance back to its original position. The original X and Y positions are stored in the variables nStartX and nStartY, respectively. These variables are declared and set in Code Block #4.
Code Block #2 creates an onResize() method for the current instance, this. This method updates the tOutput text field with the current width and height of the Stage class. This value changes, depending on the scaleMode of the Stage class. The X and Y position of the mcMenu i nstance is then updated to align the instance with the top-left corner of the area allocated to the Flash Player. If the window containing the
Chapter 20 ♦ The Stage and ContextMenu Classes 515
Flash movie is larger than the original dimensions of the movie, these values are always negative — thus, placing them to the left of the actual movie area defined by the Document Properties.
Code Block #3, as shown in previous exercises of this chapter, assigns the changeScale() method as the callback handler for the click event of the Button component instances.
In Code Block #4, the code calculates the initial position of the mcMenu i nstance. Remember that in this lesson, you are moving an element, the mcMenu i nstance, to the left edge of the browser window, regardless of the window’s size. If you want to reset the mcMenu instance back to its original position, you can refer to nStartX and nStartY.
Code Block #5 sets the scaleMode to "showAll" to get an accurate measure of the true width and height of the Flash movie. The width and height values of the Stage class (in "showAll" mode) are then stored in nMovieWidth and nMovieHeight, respectively.
Code Block #6 invokes the onResize() method as soon as the mcMenu i nstance loads.
Code Block #7 adds this current instance of menuClip, mcMenu, as a listener to the Stage class. Now, whenever the window containing the Flash movie is resized, the function defined for the onResize() method is executed. The mcMenu instance is dynamically placed in the top-left corner of the current window size.
Listing 20-3: Applying the onResize() Method
// Code Block #1: Callback handler for all Button component instances this.changeScale = function(oEvent:Object):Void { var sLabel:String =; var mcOwner:MovieClip =;
Stage.scaleMode = sLabel;
tOutput.text = "W="+Stage.width+", H="+Stage.height; mcOwner._x = nStartX; mcOwner._y = nStartY;
// Code Block #2: Callback handler for Stage resizing this.onResize = function():Void {
tOutput.text = "W=" + Stage.width + ", H=" + Stage.height; this._x = (nMovieWidth - Stage.width)/2; this._y = (nMovieHeight - Stage.height)/2;
// Code Block #3: Array of Button component instances
var aComponents:Array = [cbtNoScale, cbtShowAll, cbtNoBorder, cbtExactFit]; for(var i in aComponents){
aComponents[i].addEventListener("click", this.changeScale);
Previous << 1 .. 241 242 243 244 245 246 < 247 > 248 249 250 251 252 253 .. 427 >> Next