/**
* prototype scale9GridNested :: by Andrea Giammarchi
* This prototype allows scale9Grid Flash 8 features to be usable
* with nested clips too
* __________________________________________________
* EXAMPLE WITH MOUSE MOVEMENT:
* import flash.geom.Rectangle;
* function drawRect(m:MovieClip, c:Number, xy:Number, w:Number, h:Number):Void {
* m.moveTo(xy, xy);
* m.beginFill(c, 100);
* m.lineTo(xy + w, xy);
* m.lineTo(xy + w, xy + h);
* m.lineTo(xy, xy + h);
* m.lineTo(xy, xy);
* m.endFill();
* }
* createEmptyMovieClip("movie", getNextHighestDepth());
* movie.createEmptyMovieClip("nested", getNextHighestDepth());
* movie.nested.createEmptyMovieClip("subnested", getNextHighestDepth());
* drawRect(movie, 0x000000, 0, 120, 120);
* drawRect(movie.nested, 0xDEDEDE, 0, 100, 100);
* drawRect(movie.nested.subnested, 0x565656, 0, 60, 60);
* movie._x = movie._y = 20;
* movie.scale9Grid = new Rectangle(10, 10, 100, 100);
* movie.nested.scale9Grid = new Rectangle(20, 20, 60, 60);
* movie.nested.scale9GridNested();
* movie.nested.subnested.scale9GridNested();
* function onMouseMove() {
* movie._width = _xmouse;
* movie._height = _ymouse;
* }
* --------------------------------------------------
* NOTE: to stop or remove interval use, for example,
* movie.nested.scale9GridNested(false);
* --------------------------------------------------
* @type ActionScript 2.0 code
* @version 0.1
* @author Andrea Giammarchi
* @date 2006/06/25
* @site http://www.devpro.it/
*/
MovieClip.prototype.scale9GridNested = function(apply:Boolean):Void {
if(apply === false || this.__scale9GridNestedInterval)
clearInterval(this.__scale9GridNestedInterval);
else {
var nestedParents:MovieClip = this;
while(nestedParents._parent.scale9Grid instanceof Object)
nestedParents = nestedParents._parent;
this.__scale9GridNestedInterval = setInterval(
function(m:MovieClip, p:MovieClip):Void {
if(p._width > (2 * m._parent.scale9Grid.x)) {
m._x = (m._parent.scale9Grid.x / p._xscale) * 100;
m._width =
(m._parent.scale9Grid.width + (m._parent.scale9Grid.x * 2)) -
(((m._parent.scale9Grid.x / p._xscale) * 100) * 2);
}
if(p._height > (2 * m._parent.scale9Grid.y)) {
m._y = (m._parent.scale9Grid.y / p._yscale) * 100;
m._height =
(m._parent.scale9Grid.height + (m._parent.scale9Grid.y * 2)) -
(((m._parent.scale9Grid.y / p._yscale) * 100) * 2);
}
},
10, this, nestedParents
);
}
}