random code in AS2 convert to AS3,

2019-09-09 16:29发布

i try to make random quiz in flash cs5.5 for android, so i convert this AS2 code to AS3, but i have 1 error.

AS2:

stop();

benar = 0; salah = 0; total_frame = 11; array_frame = []; 
for (i=2; i<=total_frame; i++) {
    array_frame.push(i); 
}
array_frame.sort(function () {  
    return random(2) ? 1 : -1;
});
jumlah_frame = array_frame.length;

my AS3:

stop()

var benar=0;var salah=0; var jumlah_frame; var total_frame = 11; 
var array_frame = [];

var i:Number; for ( i=2; i<=total_frame; i++) {
    array_frame.push(i);
} 
array_frame.sort(function () {  
    return random(2) ? 1 : -1; 
});
jumlah_frame = array_frame.length;

my error was.. *array_frame.sort(function () { return random(2) ? 1 : -1;* 1180: Call to a possibly undefined method random.

Is my code already correct? i'm newbie in AS3, please somebody explain and correct this code or maybe teach me another effective code, thank you.. :)

2条回答
We Are One
2楼-- · 2019-09-09 16:53

random(2); is Math.floor(Math.random() * 1);

function oldrandom(n):Number
{
    return Math.round(Math.random()*(n-1));
}
查看更多
Emotional °昔
3楼-- · 2019-09-09 17:18

I guess, You should random(2); convert to int(Math.random()*2);

查看更多
登录 后发表回答