我有一个简单的功能,当你点击一个按钮,添加一个随机的X和Y位置的影片剪辑的舞台。我遇到的问题是,新的影片剪辑最终掩盖按钮。我试图改变新创建的MC的z索引是按钮的z索引下面,但这并没有解决问题。怎样才能阻止新的三菱商事的,从覆盖了一个已经存在的元素。
friends1_btn.addEventListener(MouseEvent.CLICK,friendMaker);
功能friendMaker(EVT:MouseEvent)方法:无效{
VAR newFriend:泰迪=新泰迪();
newFriend.x =的Math.random()* stage.width;
newFriend.y =的Math.random()* stage.height;
newFriend.z = 0;
stage.addChild(newFriend);
}
解决方案
或者可以选择 - 也许更长期的使用 - 没有所有添加的对象为同一层的按钮,儿童
代替所以:
阶段
|
+ ---对象1
|
+ - 对象2
|
+ - 键
|
+ ---对象3
有:
阶段
|
+ ---对象层
| |
| + ---对象1
| |
| + - 对象2
|
+ - 键
甚至
阶段
|
+ ---对象层
| |
| + ---对象1
| |
| + - 对象2
|
+ - 按键层
|
+ - 键
其中,对象层
和按钮层
可能仅仅是雪碧
对象,即:
VAR objectLayer:雪碧=新的Sprite();
VAR buttonLayer:雪碧=新的Sprite();
stage.addChild(objectLayer);
stage.addChild(buttonLayer);
buttonLayer.addChild(myButton的);
等等。
我想你会发现它更有助于进入长期的思考,而不是仅仅围绕转变的z指数的方式。
顺便说一句,更新的Flash Player 10中的确实的有 .Z
属性(即使它不是在文档中) - 为鲁本说,它使用新的3D转换。可悲的是3D转换没有任何支持的Z分类或Z层次感,所以不要在这种情况下提供帮助。
I have a simple function that, when you click on a button, adds a movie clip to the stage in a random x and y position. The issue I am having is that the new movie clips eventually cover up the button. I tried to change the z-index of the newly created mc to be below the z-index of the button, but that doesn't solve the problem. How does one stop the new mc's from covering up an element that already exists.
friends1_btn.addEventListener(MouseEvent.CLICK, friendMaker);
function friendMaker(evt:MouseEvent):void {
var newFriend:Teddy = new Teddy();
newFriend.x = Math.random()*stage.width;
newFriend.y = Math.random()*stage.height;
newFriend.z = 0;
stage.addChild(newFriend);
}
解决方案
Or alternatively - and maybe more use longterm - don't have all the added objects as children of the same layer as the button.
So instead of:
stage
|
+--- object 1
|
+--- object 2
|
+--- button
|
+--- object 3
Have:
stage
|
+--- object layer
| |
| +--- object 1
| |
| +--- object 2
|
+--- button
Or even:
stage
|
+--- object layer
| |
| +--- object 1
| |
| +--- object 2
|
+--- button layer
|
+--- button
Where object layer
and button layer
could simply be Sprite
objects, i.e.:
var objectLayer:Sprite=new Sprite();
var buttonLayer:Sprite=new Sprite();
stage.addChild(objectLayer);
stage.addChild(buttonLayer);
buttonLayer.addChild(myButton);
and so on.
I think you'll find it's more useful to get into that way of thinking longterm rather than just to shift the z-indices around.
Incidentally, the updated Flash Player 10 does have a .z
property (even though it's not in the documentation) - as Reuben says, it's used for the new 3D transforms. Sadly 3D transforms have no support whatsoever for z-sorting or z layering, so don't help in this case.