Actionscript 3 setting multiple variables of an object in an array possible?

人走茶凉 提交于 2019-12-13 16:12:25

问题


Right now, I have many MovieClips's in my array. I want to update all the alpha values of the MovieClips in my array.

Right now, I am using a for loop but this is not the fastest way to do it.

Is there a way to set values for all the items in my array?

Thanks!


回答1:


No. ActionScript doesn't have any constructs that allow you to change properties of all elements of the array with a single line of code. There is an Array.forEach() method, but I think that would be slower than a simple for(i = 0; i < len; i++) loop as there is an overhead of calling a function for each item of the array.




回答2:


You'll have to iterate through all the MovieClips anyway, even if there was a language structure for ease of typing.




回答3:


for each(var m:MovieClip in myArray) {
    m.alpha = 0.3;
}

a for loop isn't bad.



来源:https://stackoverflow.com/questions/2130569/actionscript-3-setting-multiple-variables-of-an-object-in-an-array-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!