ActionScript 3:按钮始终在顶部



我正在从事一个小游戏。因此,我的主距离需要4层。底层是一个带有一些按钮的MovieClip。在上面的两层中,也有效果和动作的Movieclips,顶部的层是用于ActionScript。层的序列是打算的。

当我测试它时,我无法单击任何按钮,因为可以肯定的是上面有MovieClips。ActionScript是否有可能说所有按钮始终位于顶部?

您可以通过设置parent.setChildIndex(childObject,i)来更改z索引。设置一个非常高的索引,以确保其始终在顶部

http://help.adobe.com/en_us/flashplatform/reference/referenct/actionscript/3/all-index-z.html

您也可以每次在您的一个按钮上添加新的displayObject/displayObjectContainer时呼叫AddChild ...

如果您的按钮存储在向量中,则如下:

var buttons:Vector.<SimpleButton> = new Vector.<SimpleButton>();

和您的功能之类的功能

function setButtonsOnTop():void{
    for(var i:uint=0;i<buttons.length;i++){
        addChild(buttons[i]);
    }
}

在按钮上添加某些内容时调用功能。

setButtonsOnTop();

因此,按钮始终在其他displayObject上方...

要删除按钮,您可以通过添加" RemoveButtons"方法来执行此操作:

function removeButtons():void{
    for(var i:uint=0;i<buttons.length;i++){
        removeChild(buttons[i]);
    }
}

因此,这样您不必关心索引值。

最新更新