ActionScript 3.0
从本质上讲,我需要一个函数来显示随机数量的蝶形对象。(我还应该创建一个重置函数来重置第一个函数。)
我发现,虽然一开始就没有显示这些蝴蝶,但即使我使用了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);
//发布于 2013-10-13 01:50:49
我不是很确定,但是你不是应该设置sprite的宽度和高度吗?
var bContainer: Sprite = new Sprite();
bContainer.graphics.beginFill(0xffffff);
bContainer.graphics.drawRect(0, 0,stage.stageWidth, stage.stageHeight);
addChildAt(bContainer, 0);https://stackoverflow.com/questions/19337270
复制相似问题