有人可以向我解释这个ActionScript代码行吗?

时间:2011-03-25 21:20:01

标签: actionscript flash

var loc3:* = Math.min(Math.max(arg2 / arg1.things,0),1);

如果有人可以分解这行代码正在做什么,我会非常感激。

1 个答案:

答案 0 :(得分:1)

您可以按以下步骤重写它:

VALUE1 = arg2 / arg1.things      // STEP 1   divide arg2 by arg1.things
VALUE2 = Math.max(VALUE1, 0)     // STEP 2   if the value of the division at step 1
                                            is less then 0, set the value to 0
VALUE3 = Math.min(VALUE2, 1)     // STEP 3   if the value is greater than 1
                                            set the value to 1
VALUE4 = loc3 * VALUE3           // STEP 4   multiply the value by the current value 
                                             stored in loc3
var loc3 = VALUE4;               // STEP 5   and set the final value back to loc3

因此,总而言之,代码行的作用是将arg2的值除以arg1.things中存储的值,并将结果限制在闭区间[0,1]和然后它将存储在loc3中的值乘以除法的上限计算结果。最终结果存储在loc3变量中。

相关问题