2011年9月24日 星期六

ActionScript 進位語法

var NNN:Number; /*宣告變數*/

function GOGO(e:MouseEvent){
NNN=Math.ceil(Math.random()*8); /*產生1~8亂數整數*/
SHOW_txt.text=String(NNN); /*將數字(Number)轉換成String並輸出*/
    }

AA_btn.addEventListener(MouseEvent.CLICK,GOGO); /*按AA按鈕產生亂數整數*/

Math.random(); 產生小數點亂數0.1234567895852….
Math.round(); 四捨五入
Math.floor(); 取最小整數 (如上換為floor則產生0~7)
Math.ceil(); 取最大整數

沒有留言:

張貼留言