EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 559

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Understanding scaling and slice guides 559
13. Add the following ActionScript to Frame 1 of the main Timeline:
import mx.controls.Button;
import flash.geom.Rectangle;
var grid:Rectangle = new Rectangle(100, 100, 100, 100);
var small_button:Button = this.createClassObject(Button, "small_button",
10, {label:"Small"});
small_button.move(10, 10);
small_button.addEventListener("click", smallHandler);
function smallHandler(eventObj:Object):Void {
my_mc._width = 100;
my_mc._height = 100;
}
var large_button:Button = this.createClassObject(Button, "large_button",
20, {label:"Large"});
large_button.move(120, 10);
large_button.addEventListener("click", largeHandler);
function largeHandler(eventObj:Object):Void {
my_mc._width = 450;
my_mc._height = 300;
}
var toggle_button:Button = this.createClassObject(Button,
"toggle_button", 30, {label:"scale9Grid=OFF", toggle:true,
selected:false});
toggle_button.move(420, 10);
toggle_button.setSize(120, 22);
toggle_button.addEventListener("click", toggleListener);
function toggleListener(eventObj:Object):Void {
if (eventObj.target.selected) {
eventObj.target.label = "scale9Grid=ON";
my_mc.scale9Grid = grid;
} else {
eventObj.target.label = "scale9Grid=OFF";
my_mc.scale9Grid = undefined;
}
}
The preceding code is separated into five sections. The first section of code imports two
classes: mx.controls.Button (the Button component class) and flash.geom.Rectangle. The
second section of code creates a new Rectangle class instance and specifies x and y
coordinates of 100 pixels as well as a width and height of 100 pixels. This rectangle
instance is used to set up the 9-slice scaling grid for a movie clip shape created later on.

Table of Contents

Related product manuals