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

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 .. 141 142 143 144 145 146 < 147 > 148 149 150 151 152 153 .. 427 >> Next

var aColors:Array = [0xFEEFD6, 0xEDFED6, 0xDED7FD, 0xFED6ED,
0xFFD5D5];
makeColorOptions(aColors);
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});
makeBoxAndSides(aSides);
addBoxMethod();
mcShape.mcBox.drawSquare();
mcShape._x = Stage.width/2 - mcShape._width/2; mcShape._y = Stage.height/2 - mcShape._height/2;
Chapter 10 ♦ The Drawing API 279
function makeBoxAndSides(aSides:Array) {
this.createEmptyMovieClip("mcShape", this.getNextHighestDepth()); mcShape.createEmptyMovieClip("mcBox", mcShape.getNextHighestDepth()); var mcSide:MovieClip = null; var duDrawer:DrawingUtils = null; for(var i:Number = 0; i < aSides.length; i++) { mcShape.createEmptyMovieClip(aSides[i].name, ^ mcShape.getNextHighestDepth());
mcSide = mcShape[aSides[i].name]; duDrawer = new DrawingUtils(mcSide); duDrawer.lineStyle(0, 0, 0); duDrawer.beginFill(0, 30); duDrawer.drawRectangle(100, 10, 50, 5); mcSide.useHandCursor = false; mcSide.x = aSides[i].x; mcSide.y = aSides[i].y; mcSide.rotation = aSides[i].rotation; mcSide.onRollOver = function():Void { if(this._parent.current == this) { return;
}
this._parent.current.reset(); this._parent.current = this; this.startDrag(true);
this.interval = setInterval(this._parent.mcBox, "drawSquare",
10);
};
mcSide.reset = function():Void { this._y = this.y; this._x = this.x; this._rotation = this.rotation; this.stopDrag(); clearlnterval(this.interval);
};
mcSide.reset();
}
addBoxMethod();
mcShape.mcBox.drawSquare();
mcShape._x = Stage.width/2 - mcShape._width/2; mcShape._y = Stage.height/2 - mcShape._height/2;
}
function makeColorOptions(aColors:Array):Void { for(var i:Number = 0; i < aColors.length; i++) { this.createEmptyMovieClip("mcColorSwatch" + i, ^ this.getNextHighestDepth());
mcSwatch = this["mcColorSwatch" + i]; mcSwatch.colorVal = aColors[i]; duDrawer = new DrawingUtils(mcSwatch); duDrawer.beginFill(aColors[i], 100);
280 Part III ♦ MovieClip, Button, and Drawing API
duDrawer.drawRectangle(15, 15, 7.5, 7.5);
duDrawer.endFill();
mcSwatch._x = 30;
mcSwatch._y = 20 * i + 30;
mcSwatch.onRelease = function():Void {
this._parent.nSelectedColor = this.colorVal; this._parent.mcShape.mcBox.drawSquare();
};
}
}
function addBoxMethod():Void {
mcShape.mcBox.drawSquare = function():Void {
var oRight:Object = {x:this._parent.mcRight._x - 10, ^ y:this._parent.mcRight._y};
var oBottom:Object = {x:this._parent.mcBottom._x, ^ y:this._parent.mcBottom._y};
var oLeft:Object = {x:this._parent.mcLeft._x, ^ y:this._parent.mcLeft._y};
var oTop:Object = {x:this._parent.mcTop._x, ^ y:this._parent.mcTop._y + 10};
var nMx:Number = this._xmouse; var nMy:Number = this._ymouse; switch (this._parent.current._name) { case "mcRight":
if(nMx > 110) {
this._parent.current.reset(); this._parent.current = null;
}
if(nMx < 25) { nMx = 25;
}
else if(nMx > 100) { nMx = 100;
}
if(nMy < 25) { nMy = 25;
}
else if(nMy > 75) { nMy = 75;
}
oRight.x = 2*nMx - 100;
oRight.y = 2*nMy - 50;
break; case "mcBottom":
if(nMy > 110) {
this._parent.current.reset(); this._parent.current = null;
}
if(nMx < 25) { nMx = 25;
Chapter 10 ♦ The Drawing API 281
}
else if(nMx > 75) { nMx = 75;
}
if(nMy < 25) { nMy = 25;
}
else if(nMy > 100) { nMy = 100;
}
oBottom.x = 2*nMx - 50; oBottom.y = 2*nMy - 100; break; case "mcLeft":
if(this._parent._xmouse < -10) { this._parent.current.reset(); this._parent.current = null;
}
if(nMx < 0) { nMx = 0;
}
else if(nMx > 75) { nMx = 75;
}
if(nMy < 25) { nMy = 25;
}
else if(nMy > 75) { nMy = 75;
}
oLeft.x = 2*nMx; oLeft.y = 2*nMy - (.5 * 100); break; case "mcTop":
if(this._parent._ymouse < -10) { this._parent.current.reset(); this._parent.current = null;
}
if(nMx < 25) { nMx = 25;
}
else if(nMx > 75) { nMx = 75;
}
if(nMy < 0) { nMy = 0;
}
else if(nMy > 75) { nMy = 75;
}
oTop.x = 2*nMx - (.5 * 100);
282
Part III ♦ MovieClip, Button, and Drawing API
oTop.y = 2*nMy; break;
}
this.clear();
this.lineStyle(0, 0, 100); this.beginFill(nSelectedColor, 100); this.curveTo(oTop.x, oTop.y, 100, 0); this.curveTo(oRight.x, oRight.y, 100, 100); this.curveTo(oBottom.x, oBottom.y, 0, 100); this.curveTo(oLeft.x, oLeft.y, 0, 0); this.endFill(); updateAfterEvent();
};
}
3. Save the document as responsiveBox001.fla and test the movie.
When you test the movie you should initially see a large square in the center, and five smaller squares on the left side, as shown in Figure 10-17. The large square is the responsive object that will reshape according to the mouse movement. The five smaller squares allow you to select a new color for the responsive square.
Li




Figure 10-17: The initial appearance of responsiveBox.swf
When you move the mouse so that it touches one of the sides of the square, you’ll see that it pushes the side inward as shown in Figure 10-18.
Previous << 1 .. 141 142 143 144 145 146 < 147 > 148 149 150 151 152 153 .. 427 >> Next