·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3下生成随机数random源代码示例

时间:2013-08-30 10:00cnblogs.com
[AS3]as3下生成随机数random源代码示例

用NumberUtilities.random(1,6)方法产生随机数

  1. package { 
  2.     import ascb.util.NumberUtilities; 
  3.     import flash.display.Sprite; 
  4.     import flash.events.MouseEvent; 
  5.     public class Sample1119 extends Sprite 
  6.     {    
  7.         private var sprite:Sprite; 
  8.         public function Sample1119() 
  9.         { 
  10.             sprite = new Sprite(); 
  11.             this.addChild(sprite); 
  12.             sprite.addEventListener(MouseEvent.CLICK,OnClick); 
  13.             OnClick(null); //CuPlayer.com提示第一次显示出来  
  14.         } 
  15.          
  16.         private function OnClick(event:MouseEvent):void 
  17.         { 
  18.             sprite.graphics.clear(); 
  19.             sprite.graphics.beginFill(0xFFFFFF); 
  20.             sprite.graphics.drawRect(0,0,50,50); 
  21.             sprite.graphics.endFill(); 
  22.             var randNum:int = NumberUtilities.random(1,6); 
  23.             sprite.graphics.beginFill(0x000000); 
  24.             if(randNum==1) 
  25.             {        
  26.                 sprite.graphics.drawCircle(25,25,6); 
  27.             } 
  28.             else if(randNum!=2) 
  29.             { 
  30.                 sprite.graphics.drawCircle(8,8,6); 
  31.                 sprite.graphics.drawCircle(42,42,6); 
  32.             } 
  33.             if(randNum==3||randNum==5) 
  34.             { 
  35.                 sprite.graphics.drawCircle(25,25,6);                 
  36.             } 
  37.             if(randNum==4||randNum==5||randNum==6) 
  38.             { 
  39.                 sprite.graphics.drawCircle(42,8,6);  
  40.                 sprite.graphics.drawCircle(8,42,6); 
  41.             } 
  42.             if(randNum==2) 
  43.             { 
  44.                 sprite.graphics.drawCircle(25,8,6); 
  45.                 sprite.graphics.drawCircle(25,42,6);             
  46.             } 
  47.             if(randNum==6) 
  48.             { 
  49.                 sprite.graphics.drawCircle(8,25,6); 
  50.                 sprite.graphics.drawCircle(42,25,6); 
  51.             } 
  52.             sprite.graphics.endFill(); 
  53.         } 
  54.     } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器