先看帮助文件,本人英语水平有限,看不懂请自行猜测或者对照原文。
scale9Grid (MovieClip.scale9Grid property)
The area in the upper-left corner outside the rectangle
The area above the rectangle
The area in the upper-right corner outside the rectangle
The area to the left of the rectangle
The area to the right of the rectangle
The area in the lower-left corner outside the rectangle
The area below the rectangle
The area in the lower-right corner outside the rectangle //几个区域的位置。
----------------
scale9Grid (MovieClip.scale9Grid property)
public scale9Grid : Rectangle(矩形)
The rectangular region that defines the nine scaling regions for the movie clip. If set to null, the entire movie clip scales normally when any scale transformation is applied.
/*矩形区域为movie clip定义了9个缩放区域。如果这个值被设为null,则整个movie clip在任何缩放转换被应用时,将会被正常缩放。*/
When a scale9Grid property is defined for a movie clip, the movie clip is divided into a grid with nine regions, based on the scale9Grid rectangle, which defines the center region of the grid.
/*当一个movie clip被定义了一个scale9Grid,这个movie clip将在scale9Grid定义的中心区域栅格的基础上被分成一个包含9个区域的栅格。*/
The rectangular region that defines the nine scaling regions for the movie clip. If set to null, the entire movie clip scales normally when any scale transformation is applied.
/*矩形区域为movie clip定义了9个缩放区域。如果这个值被设为null,则整个movie clip在任何缩放转换被应用时,将会被正常缩放。*/
When a scale9Grid property is defined for a movie clip, the movie clip is divided into a grid with nine regions, based on the scale9Grid rectangle, which defines the center region of the grid.
/*当一个movie clip被定义了一个scale9Grid,这个movie clip将在scale9Grid定义的中心区域栅格的基础上被分成一个包含9个区域的栅格。*/
You can think of the eight regions outside of the center (defined by the rectangle) as being like a picture frame that has special rules applied to it when the movie clip is scaled.
//你可以想想这处于中心周围的8个区域(矩形)就像一个图片帧当movie clip被缩放时被应用了特殊的规则。
When the scale9Grid property is set and a movie clip is scaled, all text and child movie clips scale normally, regardless of which regions of the scale9 grid they are located in
//当一个movie clip被设置了scale9Grid属性而且被缩放时,movie clip内部的所有text和子movie clip将同时被正常缩放,而无需关心那9个区域具体在哪里。
//你可以想想这处于中心周围的8个区域(矩形)就像一个图片帧当movie clip被缩放时被应用了特殊的规则。
When the scale9Grid property is set and a movie clip is scaled, all text and child movie clips scale normally, regardless of which regions of the scale9 grid they are located in
//当一个movie clip被设置了scale9Grid属性而且被缩放时,movie clip内部的所有text和子movie clip将同时被正常缩放,而无需关心那9个区域具体在哪里。
MovieClip类有了scale9Grid属性让我们可以做出更加自由、交互性更强的作品,活活。
给scale9framedpicture.fla的AS加上注释,是翻译的。
Stage.scaleMode = ’noScale’;
/*
9-slice scaling grids applied manually in movie clip symbol
using constant border width. Scaling the image will cause
the border within that picture to retain that width
9-slice (9-薄片)手动缩放使用常量边界宽度栅格应用于movie clip symbol
缩放图片将导致边界进入图片内部以保持边界宽度。
*/
var border = picture_mc.scale9Grid.x; // start of scale9Grid x gives border size (since constant)
//scale9Grid.x的属性赋予边界尺寸。
// a "manipulate" point is now created to help in determining how the
// image is being scaled when clicked. if scaling left, x will be -1
// if scaling right, x will be +1 and if no x scaling is being done,
// x will be 0; the same applies to y.
//现在创建一个操作点帮助确定当图片被点击时是怎样被缩放的。
//如果向左缩放,则x是-1,如果向右缩放,则x是+1,如果没有x轴缩放,则x是0
//同样应用于Y轴。
var manipulate = new flash.geom.Point(0,0);
// two mouse variables (old & new) are used to store the
// location of the mouse for scaling. These are compared
// when scaling to see how far the mouse has moved
//两个鼠标变量(old&new)将用来保存缩放时鼠标的位置
//当进行缩放时它们用来比较,让我们知道鼠标移动了多远。
//flash.geom.Point是Object类的子类,用于定义2维平面坐标,这里不作介绍。
var old_mouse;
var new_mouse;
// picture is pressed and being scaled (or moved)
//当图片被点击和缩放(或移动)。
picture_mc.onPress = function(){
// find the bounds of the picture clip
// this will be used to compare with the
// border property defined earlier to see
// where the picture is being clicked
//查找图片剪辑的范围,这个将用来和边界属性比较得出图片哪里被点击了。
var bounds = this.getBounds(this._parent);
// update manipulate’s x property depending on
// whether or not the user clicked the left or
// right borders
//根据使用者是否点击左边或右边边界更新操作点X属性
if (_xmouse < bounds.xMin + border) manipulate.x = -1;
else if (_xmouse > bounds.xMax - border) manipulate.x = 1;
else manipulate.x = 0;
// update manipulate’s y property depending on
// whether or not the user clicked the top or
// bottom borders
//根据使用者是否点击顶部或底部边界更新操作点Y属性
if (_ymouse < bounds.yMin + border) manipulate.y = -1;
else if (_ymouse > bounds.yMax - border) manipulate.y = 1;
else manipulate.y = 0;
// record the mouse position
//记录鼠标坐标。
old_mouse = new flash.geom.Point(_xmouse, _ymouse);
// set the onMouseMove event to scale when the mouse is moved
//设置onMouseMove事件用来缩放图片。
this.onMouseMove = scalePictureMouseMove;
}
// delete the mouse move when released
//当鼠标离开MC时删除onMouseMove事件。
picture_mc.onRelease = picture_mc.onReleaseOutside = function(){
delete this.onMouseMove;
}
// when moving the mouse in scaling or moving the picture
//设置鼠标缩放、移动方法。
function scalePictureMouseMove(){
// record the current mouse position
//记录鼠标当前坐标
new_mouse = new flash.geom.Point(_xmouse, _ymouse);
// find the difference between the old mouse
// position and the new one
//取得鼠标移动坐标差值
var diff_mouse = new_mouse.subtract(old_mouse);
// adjust the width and height of the picture
// the use of manipulate makes this easy allowing
// you to just multiply it by the difference
// in mouse position. if the user did not click
// on a border, manipulate would be 0 and there
// would be no change
//调节图片宽度&高度。
//使用操作点可以轻易的允许你只要把鼠标坐标差值乘以它。
//如果使用者没有点击边界,那么操作点将一直是0而不会改变。
this._width += manipulate.x * diff_mouse.x;
this._height += manipulate.y * diff_mouse.y;
// determine if the user clicked on a border
// if not, the user is dragging (moving) the image
//确认使用者点击了边界,如果没有则使用者在拖动图片。
var isDragging = Boolean(manipulate.x == 0 && manipulate.y == 0);
// if the user is scaling left or up from a left
// or top border, or if the user is dragging the
// picture, offset the x and/or y position
// of the picture to compensate
//如果使用者点击左边界向左缩放或点击顶边界向上缩放,
//或者使用者正在拖动图片,偏移图片的X&/或Y坐标以平衡。
if (manipulate.x < 0 || isDragging) this._x += diff_mouse.x;
if (manipulate.y < 0 || isDragging) this._y += diff_mouse.y;
// set the old mouse to the current mouse so that it
// can be used for the next onMouseMove event
//设置old_mouse变量为当前值,以用于下一个onMouseMove事件。
old_mouse = new_mouse;
}
/*
9-slice scaling grids applied manually in movie clip symbol
using constant border width. Scaling the image will cause
the border within that picture to retain that width
9-slice (9-薄片)手动缩放使用常量边界宽度栅格应用于movie clip symbol
缩放图片将导致边界进入图片内部以保持边界宽度。
*/
var border = picture_mc.scale9Grid.x; // start of scale9Grid x gives border size (since constant)
//scale9Grid.x的属性赋予边界尺寸。
// a "manipulate" point is now created to help in determining how the
// image is being scaled when clicked. if scaling left, x will be -1
// if scaling right, x will be +1 and if no x scaling is being done,
// x will be 0; the same applies to y.
//现在创建一个操作点帮助确定当图片被点击时是怎样被缩放的。
//如果向左缩放,则x是-1,如果向右缩放,则x是+1,如果没有x轴缩放,则x是0
//同样应用于Y轴。
var manipulate = new flash.geom.Point(0,0);
// two mouse variables (old & new) are used to store the
// location of the mouse for scaling. These are compared
// when scaling to see how far the mouse has moved
//两个鼠标变量(old&new)将用来保存缩放时鼠标的位置
//当进行缩放时它们用来比较,让我们知道鼠标移动了多远。
//flash.geom.Point是Object类的子类,用于定义2维平面坐标,这里不作介绍。
var old_mouse;
var new_mouse;
// picture is pressed and being scaled (or moved)
//当图片被点击和缩放(或移动)。
picture_mc.onPress = function(){
// find the bounds of the picture clip
// this will be used to compare with the
// border property defined earlier to see
// where the picture is being clicked
//查找图片剪辑的范围,这个将用来和边界属性比较得出图片哪里被点击了。
var bounds = this.getBounds(this._parent);
// update manipulate’s x property depending on
// whether or not the user clicked the left or
// right borders
//根据使用者是否点击左边或右边边界更新操作点X属性
if (_xmouse < bounds.xMin + border) manipulate.x = -1;
else if (_xmouse > bounds.xMax - border) manipulate.x = 1;
else manipulate.x = 0;
// update manipulate’s y property depending on
// whether or not the user clicked the top or
// bottom borders
//根据使用者是否点击顶部或底部边界更新操作点Y属性
if (_ymouse < bounds.yMin + border) manipulate.y = -1;
else if (_ymouse > bounds.yMax - border) manipulate.y = 1;
else manipulate.y = 0;
// record the mouse position
//记录鼠标坐标。
old_mouse = new flash.geom.Point(_xmouse, _ymouse);
// set the onMouseMove event to scale when the mouse is moved
//设置onMouseMove事件用来缩放图片。
this.onMouseMove = scalePictureMouseMove;
}
// delete the mouse move when released
//当鼠标离开MC时删除onMouseMove事件。
picture_mc.onRelease = picture_mc.onReleaseOutside = function(){
delete this.onMouseMove;
}
// when moving the mouse in scaling or moving the picture
//设置鼠标缩放、移动方法。
function scalePictureMouseMove(){
// record the current mouse position
//记录鼠标当前坐标
new_mouse = new flash.geom.Point(_xmouse, _ymouse);
// find the difference between the old mouse
// position and the new one
//取得鼠标移动坐标差值
var diff_mouse = new_mouse.subtract(old_mouse);
// adjust the width and height of the picture
// the use of manipulate makes this easy allowing
// you to just multiply it by the difference
// in mouse position. if the user did not click
// on a border, manipulate would be 0 and there
// would be no change
//调节图片宽度&高度。
//使用操作点可以轻易的允许你只要把鼠标坐标差值乘以它。
//如果使用者没有点击边界,那么操作点将一直是0而不会改变。
this._width += manipulate.x * diff_mouse.x;
this._height += manipulate.y * diff_mouse.y;
// determine if the user clicked on a border
// if not, the user is dragging (moving) the image
//确认使用者点击了边界,如果没有则使用者在拖动图片。
var isDragging = Boolean(manipulate.x == 0 && manipulate.y == 0);
// if the user is scaling left or up from a left
// or top border, or if the user is dragging the
// picture, offset the x and/or y position
// of the picture to compensate
//如果使用者点击左边界向左缩放或点击顶边界向上缩放,
//或者使用者正在拖动图片,偏移图片的X&/或Y坐标以平衡。
if (manipulate.x < 0 || isDragging) this._x += diff_mouse.x;
if (manipulate.y < 0 || isDragging) this._y += diff_mouse.y;
// set the old mouse to the current mouse so that it
// can be used for the next onMouseMove event
//设置old_mouse变量为当前值,以用于下一个onMouseMove事件。
old_mouse = new_mouse;
}
