2013-10-12 49 views
0

ActionScript 3.0AS3顯示對象和精靈(添加基於隨機數的孩子)

基本上我需要一個顯示隨機數的蝴蝶對象的函數。 (另外,我應該做一個復位功能,重置第一個功能。)

雖然我發現雖然蝴蝶甚至沒有顯示開始,似乎孩子們沒有被添加到舞臺上,即使我用了的addChild()。

任何幫助表示感謝!

//隨機數

 var randomNumber : int = Math.floor(Math.random() * 8); 

// New Sprite 

     var bContainer: Sprite = new Sprite(); 
     this.addChild(bContainer); 

     var butterfly: MovieClip = new Butterfly(); 
     bContainer.addChild(butterfly); 

//Function to Create Butterfly Objects: 

     function showButterfly(randomNumber:int):void { 

      while(bContainer.numChildren < randomNumber){ 
       bContainer.addChild(butterfly); 
      } 

//Reset Function, I am not sure about this (especially the second one) 

     function button(evt:MouseEvent): void { 

       if(numChildren>0) { 
        removeChildAt(0); 
       } 

       if(numChildren==0) { 
        showButterfly(); 
       } 
     } 

// Event Listener 

     button.addEventListener(MouseEvent.MOUSE_DOWN); 
// 

回答

0

我不能完全肯定,但不是你想設置的寬度和高度,它作爲一個容器對象精靈?

var bContainer: Sprite = new Sprite(); 
bContainer.graphics.beginFill(0xffffff); 
bContainer.graphics.drawRect(0, 0,stage.stageWidth, stage.stageHeight); 
addChildAt(bContainer, 0);