flex with 关键字用法

xiaoxiao2022-06-14  69

以下示例首先设置 someOther_mc 实例的 _x 和 _y 属性,然后指示 someOther_mc 转到第 3 帧并停止。

with (someOther_mc) { _x = 50; _y = 100; gotoAndStop(3); } 以下代码段显示在不使用 with 语句的情况下如何编写先前的代码。 someOther_mc._x = 50; someOther_mc._y = 100; someOther_mc.gotoAndStop(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 */
转载请注明原文地址: https://www.6miu.com/read-4936618.html

最新回复(0)