作者cantuse (不会用)
看板Flash
标题Re: [问题] 回圈的变数去传参数的问题
时间Sun Sep 16 20:43:06 2007
※ 引述《etrexetrex (ETREX)》之铭言:
: ※ 引述《cantuse (不会用)》之铭言:
: : 请问各位高手
: : 底下这段程式
: : 我是爬过文 用了拆字串的方法
: : 去让i这个变数
: : 变成当"store"+i+"_mc" 被rollover
: : 所呼叫方法rollOverIt(i)传的一个参数
: : for (i=1; i<=200; i++) {
: : eval("_root.store_mc.store"+i+"_mc").onRollOver = function() {
: 可改为 var MC = _root["store_mc.store"+i+"_mc"];
: MC.i=i;
: MC.onRollOver = function(){
: rollOverIt(this.i);
: } ^^^^^^
: : rollOverIt(int(this._name.substr(5, 1)));
: : };
: : }
: : 可以请教的是
: : 1.我没设想到万一变数i超过二位数 那传递的永远都是1-9了
: : 请问有更好的方法吗?
: 有
: : 2.还有就是想请问 为什麽直接用rollOverIt(i)
: : 得到的永远都是最後一个数字ex200?
: 当onRollOver执行时,for回圈势必先跑完,i永远是最後一个数字
: 所以让i变成MC的属性就没问题惹
: : 最後感谢大家
: : 谢谢
恩 真的很谢谢您
只是我还以为写成这样↓
for (i=1; i<=200; i++) {
eval("_root.store_mc.store"+i+"_mc").onRollOver = function() {
rollOverIt(i);
}
}
程式就会就会跑出
_root.store_mc.store1_mc.onRollOver = function() {
rollOverIt(1);
}
_root.store_mc.store2_mc.onRollOver = function() {
rollOverIt(2);
}
_root.store_mc.store3_mc.onRollOver = function() {
rollOverIt(3);
}
.
.
.
.
.
.
.
_root.store_mc.store200_mc.onRollOver = function() {
rollOverIt(200);
}
为什麽跑出来的还是
_root.store_mc.store1_mc.onRollOver = function() {
rollOverIt(i);
}
呢?
是因为它是参数的关系吗??
谢谢^^
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.117.100.53