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

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 135 136 137 138 139 140 < 141 > 142 143 144 145 146 147 .. 419 >> Next

duClickDrawer.drawRectangle(mcTwo._width, mcTwo._height, ^ mcTwo._width/2, mcTwo._height/2); mcClickNext.mask = mcMask; mcClickNext.onRelease = function():Void { if(this.mask.interval == null) {
this.mask.interval = setInterval(this.mask, "slide", 10);
4. Save the document and test the movie.
When you test the movie, you should be able to click the stage and see a simple wipe occur between the two images. Click again and the application will wipe between the images again.
Now that youíve had a chance to see the application work, take a closer look at the code.
First, of course, you use the attachMovie() method to add the two instances to the stage. You name them mcOne and mcTwo, where mcTwo has the higher depth of the two and thus appears above mcOne.
Chapter 10 ¶ The Drawing API 277
this.attachMovie("ImageOneSymbol", "mcOne", this.getNextHighestDepth()); this.attachMovie("ImageTwoSymbol", "mcTwo", this.getNextHighestDepth());
Next you create an empty MovieClip named mcMask. This is the object into which youíll draw the mask using a DrawingUtils object. Notice that the mask is a filled rectangle with the same dimensions as mcTwo.
this.createEmptyMovieClip("mcMask", this.getNextHighestDepth()); var duMaskDrawer:DrawingUtils = new DrawingUtils(mcMask); duMaskDrawer.beginFill(0, 0);
duMaskDrawer.drawRectangle(mcTwo._width, mcTwo._height, ^ mcTwo._width/2, mcTwo._height/2);
You use the setMask() method to assign mcMask as the mask for mcTwo.
The direction and interval properties are two custom properties you assign to mcMask. The direction property can have a value of either off or on. This value determines whether the mask is sliding off or on mcTwo. The interval property is what youíll use to store the ID for the interval when you set the interval method.
mcMask.direction = "off"; mcMask.interval = null;
The slide() method is a custom method that animates the mask so that it slides on or off of mcTwo. First, it moves the mask by 10 pixels to the left. Then it checks to determine the direction in which the mask is moving relative to mcMask. Based on the direction, it checks to see if the mask has completed its slide. If so, it moves it to the correct resting location, clears the interval, and sets the direction to the opposite:
mcMask.slide = function():Void { this._x -= 10;
if(this.direction == "on") { i f(this._x <= 0) {
clearlnterval(this.interval); this.interval = null; this._x = 0; this.direction = "off";
else {
if(this._x < -this._width) { clearlnterval(this.interval); this.interval = null; this._x = this._width; this.direction = "on";
278 Part III ¶ MovieClip, Button, and Drawing API
In addition to creating the mask and the image MovieClip objects, you want to create another MovieClip object. This object, mcClickNext, serves as a button. You use a DrawingUtils object to draw a rectangle with the same dimensions as mcTwo. The rectangle has an alpha level of 0 so that it appears transparent. You donít want the user to see this object. Instead, it should simply enable the user to click anywhere on the stage.
this.createEmptyMovieClip("mcClickNext", this.getNextHighestDepthO); var duClickDrawer:DrawingUtils = new DrawingUtils(mcClickNext); duClickDrawer.lineStyle(0, 0, 0); duClickDrawer.beginFill(0, 0);
duClickDrawer.drawRectangle(mcTwo._width, mcTwo._height, mcTwo._width/2, mcTwo._height/2);
The mask property is a custom property to which you assign a reference to mcMask. Then, within the onRelease() method you set an interval at which the slide() method of the mask is called. You make that part conditional because you want the user to be able to set a new interval only if the previous one has completed. Otherwise, each time the user clicked, if the previous interval hadnít completed, the mask would begin to move twice as fast, and if the user clicks enough times successively, it could take its toll on the processor.
mcClickNext.mask = mcMask; mcClickNext.onRelease = function():Void { if(this.mask.interval == null) {
this.mask.interval = setInterval(this.mask, "slide", 10);
Practicing Responsive Objects
In this exercise, youíll use the Drawing API to create a square that responds to the mouse. When the user moves the mouse near a side of the square, that side will appear to be pressed in, following the movement of the mouse. Complete the following steps:
1. Open a new Flash document.
2. On the first frame of the first layer, add the following code:
var aColors:Array = [0xFEEFD6, 0xEDFED6, 0xDED7FD, 0xFED6ED,
var nSelectedColor:Number = aColors[0];
var aSides:Array = new Array();
aSides.push({name:"mcRight", y:0, x:110, rotation:90});
aSides.push({name:"mcBottom", y:100, x:0, rotation:0});
aSides.push({name:"mcLeft", y:0, x:0, rotation:90});
aSides.push({name:"mcTop", y:-10, x:0, rotation:0});
Previous << 1 .. 135 136 137 138 139 140 < 141 > 142 143 144 145 146 147 .. 419 >> Next