Name: emboss() - Embosses a movieclip at given height & angle (best with images)
Author: senocular: www.senocular.com
Date: 1899-12-31T00:05:23.800
Documentation:
Movieclip EMBOSS: Embosses a movieclip using a slightly offset
reversed value duplicate of itself at 50% alpha as an overlay
Arguments:
- height: distance of offset or emboss "height" in pixels
- angle: "angle" of emboss or direction to move emboss by factor of height
- depth: (optional) used to specify depth of duplicated clip if needed. Default is 1
Warnings:
- using this in an onClipEvent(load) event will cause flash to crash as each duplicate
will attempt to give itself its own emboss. Also be aware that any other code on the
specified clip will similarly be carried over to the duplicate used to make the emboss.
Example:
// generic button:
// when pressed, myClip in _root gets embossed
// with a height of 2 at 45 degrees
on(press){
_root.myClip.emboss(2,45)
}
// when released, the emboss is removed
on(release){
_root.myClip.emboss(0)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
MovieClip.prototype.emboss = function(height, angle, depth){
if (height){ // if first argument is not zero
if (arguments.length == 2) depth = 1; // assign optional depth value if not given
this.duplicateMovieClip(this._name +"emboss_mc",depth); // create duplicate
var dup = this._parent[this._name + "emboss_mc"]; // assign temporary variable to reference duplicate
var toRads = 180/Math.PI; // used to convert decimal values to radians
dup._x -= Math.cos(angle*toRads)*height; // determine dup offset from angle
dup._y -= Math.sin(angle*toRads)*height;
var col = new Color(dup); // create temporary color object for dup
col.setTransform({ra:-100, rb:255, ga:-100, gb:255, ba:-100, bb:255, aa:50}); // reverse colors and set alpha to 50%
}else{ // if height is zero
this._parent[this._name + "emboss_mc"].removeMovieClip(); // remove the emboss
}
}