作者Angelliya (不知...)
看板Flash
标题Re: [问题] 呼叫大量且命名有规律的function
时间Wed Sep 1 11:19:27 2010
※ 引述《aquarianboy (高 见龙)》之铭言:
: ※ 引述《justaID (快乐崇拜)》之铭言:
: : 用 / 爬过文,不知道是不是关键字不对,没有看到解答
: : (意外反而挖到一些写法的技巧,对那些高手神人的崇拜又更深一层)
: : 请问我今天有 f1()~f100() 的function
: : 想要依次对变数 x 作处理,如:
: : f1(x);
: : f2(x);
: : f3(x);
: : .....
: : .....
: : f100(x);
: : 请问有什麽写法可以组合function的名称(ex: "f"+i)
: : 用for包起来後,就能自动有次序的去呼叫function的使用?
: : 谢谢
: function a1(xx) { trace(xx); }
: function a2(xx) { trace(xx); }
: function a3(xx) { trace(xx); }
: for (var i:int = 1; i<= 3; i++)
: {
: this['a' + i]("hello");
: }
var functionArray:Array = new Array(a1,a2,a3);
function a1(xx) { trace(xx); }
function a2(xx) { trace(xx); }
function a3(xx) { trace(xx); }
var functionArrayLength:uint = functionArray.length;
for (var i:int = 0; i<functionArrayLength; i++)
{
functionArray[i]("hello");
}
我满喜欢用这个方法控制选单的
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.32.165.26
1F:推 justaID:很棒的一招!如果有两个变数分别要处理,但函数的呼叫次序 09/01 12:45
2F:→ justaID:不同,用阵列来控制次序真是好方法! 受教了! 09/01 12:46