Name: isWithin() - tests if a movieclips bounds is within the bounds of a movieclip or getBounds object
Author: senocular: www.senocular.com
Date: 1899-12-31T00:36:51.800
Documentation:
MovieClip ISWITHIN: checks to see if a movieclip within
the bounds of a) another movieclip or b) a bounds object in the
form of an object as retrieved from the movieclip.getBounds()
method
Arguments:
- cb: or 'onstraint bounds', the bounds to which this movieclip is to be tested to be in.
This can be either a movieclip or a getBounds object. As a getBounds object it doesnt have to
be an object specifically from a getBounds action, but it has to be in the same format, which
is an object containing the 4 following properties
xmin - the 'left' of the bounds, how far left this clip can go
xmax - the 'right' of the bounds, how far right this clip can go
ymin - the 'top' of the bounds, how high this clip can go
ymax - the 'bottom' of the bounds, how low this clip can go
ex:
myBounds = {xmin:0,xmax:200,ymin:10,ymax:90};
this.isWithin(myBounds);
Example:
onClipEvent(enterFrame){
// generic move movieclip around function
this.moveAboutRandomly();
// fade a movieclip out if not within the box
// fade back in when in the box
if (this.isWithin(_root.box)) _alpha++;
else _alpha--;
}
1
2
3
4
5
6
7
MovieClip.prototype.isWithin = function(cb){
if (typeof cb == "movieclip") cb = cb.getBounds(this._parent);
var tb = this.getBounds(this._parent);
if (tb.xmin < cb.xmin || tb.xmax > cb.xmax) return false;
if (tb.ymin < cb.ymin || tb.ymax > cb.ymax) return false;
return true;
}