shorten something in AS 2.0 using eval or set?
Posted
by
chris
on Stack Overflow
See other posts from Stack Overflow
or by chris
Published on 2010-12-24T03:19:29Z
Indexed on
2010/12/24
22:54 UTC
Read the original article
Hit count: 194
eval("_parent.volumetone" + target1)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target2)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target3)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target4)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target5)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target6)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target7)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target8)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target9)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target10)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target11)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target12)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target13)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target14)._yscale = Math.round(number)/1.5+50;
eval("_parent.volumetone" + target15)._yscale = Math.round(number)/1.5+50;
i have these lines of repetitive code. the variables target1 to target15 are a random number between 1 and 110. so one may point to _parent.volumetone49 and adjust its _yscale for example. the code above works the way i want, but i want it shorter.
here's something i tried with no success:
for (i = 0; i < 15; i++) {
set("_parent.volumetone" + ("target"+i) + "._xscale", Math.round(funhousenumber)/1.5+50);
}
basically having a loop that starts at 1 and goes to 15, then replaces target1 with target+i, i being 1, which would give target1 and thus the number contained in it.
maybe i have to use eval()? i'm still not sure what i'm doing but i'm learning as i go. thanks.
© Stack Overflow or respective owner