flex with 关键字用法
以下示例首先设置 someOther_mc 实例的 _x 和 _y 属性,然后指示 someOther_mc 转到第 3 帧并停止。
同时访问一个作用域链列表中的多个项时,with语句会很有用。在以下示例中,内置 Math 对象位于作用域链之前。将 Math 设置为默认对象可将标识符 cos 、sin 和 PI 分别解析为 Math.cos 、Math.sin 和 Math.PI 。标识符 a 、x 、y 和 r polar() 的对象激活范围中,所以将解析为相应的局部变量。 不是 Math 对象的方法或属性,但由于它们位于函数
function polar(r:Number):void {
var a:Number, x:Number, y:Number;
with
(Math) {
a = PI * pow(r, 2);
x = r * cos(PI);
y = r * sin(PI / 2);
}
trace("area = " + a);
trace("x = " + x);
trace("y = " + y);
} polar(3);
/*
area = 28.2743338823081
x = -3
y = 3
*/
转载:http://xiejiangbo.iteye.com/blog/459350
with
(someOther_mc) {
_x = 50;
_y = 100;
gotoAndStop(3);
}
以下代码段显示在不使用 with语句的情况下如何编写先前的代码。
someOther_mc._x = 50;
someOther_mc._y = 100;
someOther_mc.gotoAndStop(3);