Arrange (z) order of objects in Flash with ActionScript 3?

ぃ、小莉子 提交于 2019-12-19 05:59:36

问题


Is it possible to arrange (z) order of objects in Flash with ActionScript 3?

e.g. I have 3 symbol instances on a given layer, and I want to perform the equivalent of 'Bring to Front', 'Bring Forward', and/or target a certain z position.


回答1:


You can change the z-index (stacking order) of a movie clip within a same layer using action script like this.

parent.setChildIndex(childObject, i)

Change childObject to the name of the movie clip you want to change the z-index, change i to an integer (the desired z-index value).

If you want to make this happen on a mouse event, put above code inside a function and attach an event listener to a button to invoke this function on a mouse event.




回答2:


Bring to front would be something like:

myObject.parent.setChildIndex( myObject, myObject.parent.numChildren - 1);

Bring forward would be something like:

myObject.parent.setChildIndex( myObject, myObject.parent.getChildIndex( myObject ) + 1);

Setting a specific z index would be:

myObject.parent.setChildIndex( myObject, newZIndex);



来源:https://stackoverflow.com/questions/3865426/arrange-z-order-of-objects-in-flash-with-actionscript-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!