2011-10-23 115 views
1

我创建了两个空精灵作为,bottom_spr和top_sprAS3层为了

当点击一个按钮,一个影片剪辑出现,并跟随鼠标,直到你点击,那么它的位置是固定。

只要按钮被点击,我addChild MovieClip到正确的雪碧。

不幸的是,图层系统看不到工作,因为它们按照我放置的顺序进行分层,Sprites似乎没有影响它。

这怎么可能?

private var ground_spr:Sprite; 
private var units_spr:Sprite; 

public function Game() { 
addEventListeners(); 

ground_spr = new Sprite(); 
units_spr= new Sprite(); 

addChild(ground_spr); 
addChild(units_spr); 
} 

private function addEventListeners(){ 
groundBtn.addEventListener(MouseEvent.CLICK, clickGroundBtn); 
unitBtn.addEventListener(MouseEvent.CLICK, clickUnitBtn); 
} 

private function clickGroundBtn(event:MouseEvent){ 
    var ground = new Ground_mc(); 
follow(); 
ground_spr.addChild(ground); 
} 

private function clickUnitBtn(event:MouseEvent){ 
    var unit = new Unit_mc(); 
follow(); 
units_spr.addChild(unit); 
} 
+0

请张贴一些代码。 – grapefrukt

+0

我添加了一些代码。 – Kris

+0

噢,我有点为两种类型调用相同的函数,所以它确实起作用。 – Kris

回答

4

您的问题非常模糊,但我会尝试回答它。如果你澄清你想如何准确地排列物体,我可以更好地回答你的问题。如果您需要,可以在深度处理上添加抽象层。在这种情况下,我没有看到太多的需求,但我会告诉你一些你可以做的事情。

将对象添加到屏幕的背面:

this.setChildIndex(objName, 0); 

将对象添加到屏幕的前面:

this.setChildIndex(objName, this.numChildren - 1); 

要交换的两个对象的深度:

this.swapChildren(objA, objB); 
//Note this is expecting two DisplayObjects so you may have to do: 
this.swapChildren(objA as DisplayObject, objB as DisplayObject);