我想知道是否有方法讓對象A(例如Rect)從對象B(例如另一個Rect)可視地出現在對象B(例如另一個Rect)的後面,但從鼠標懸停的角度看它在它的前面。換句話說,如果您將鼠標筆尖移到A和B的交叉點上,A會翻轉而不是B.有關排序圖層的奇怪問題
如果這不是開箱即用的,我很好奇您將如何實現這樣的事情。
謝謝
我想知道是否有方法讓對象A(例如Rect)從對象B(例如另一個Rect)可視地出現在對象B(例如另一個Rect)的後面,但從鼠標懸停的角度看它在它的前面。換句話說,如果您將鼠標筆尖移到A和B的交叉點上,A會翻轉而不是B.有關排序圖層的奇怪問題
如果這不是開箱即用的,我很好奇您將如何實現這樣的事情。
謝謝
我不認爲這是內在工作。
要使ObjectA出現在ObjectB後面,只需在ObjectB之前將ObjectA添加到容器。 Flex會根據已添加到容器的訂單項來處理「Z-Order」。
我會使用swapChildren和鼠標事件來實現Z順序變化。可能mouseOver將ObjectA移動到頂部,然後mouseOut將ObjectA移動到後面。
如果您的結構更復雜且分爲兩類以上,則可以使用swapChildrenAt。
也許這個樣本適合您的需要?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
private function putBlueRectInFront():void
{
blueRect.depth = 1;
redRect.depth = 0;
}
private function putRedRectInFront():void
{
redRect.depth = 1;
blueRect.depth = 0;
}
protected function rectContainer_rollOutHandler(event:MouseEvent):void
{
rectContainer.removeEventListener(MouseEvent.MOUSE_MOVE, rectContainer_mouseMoveHandler);
putBlueRectInFront();
}
protected function rectContainer_rollOverHandler(event:MouseEvent):void
{
rectContainer.addEventListener(MouseEvent.MOUSE_MOVE, rectContainer_mouseMoveHandler);
}
private function rectContainer_mouseMoveHandler(event:MouseEvent):void
{
if (event.localX <= redRect.width && event.localY <= redRect.height)
putRedRectInFront();
else
putBlueRectInFront();
}
]]>
</fx:Script>
<s:BorderContainer height="400" horizontalCenter="0" id="rectContainer"
rollOut="rectContainer_rollOutHandler(event)" rollOver="rectContainer_rollOverHandler(event)" verticalCenter="0"
width="400">
<s:borderStroke>
<s:SolidColorStroke color="black" weight="1" />
</s:borderStroke>
<s:Rect height="250" id="redRect" left="0" top="0" width="250">
<s:fill>
<s:SolidColor color="red" />
</s:fill>
</s:Rect>
<s:Rect bottom="0" height="250" id="blueRect" right="0" width="250">
<s:fill>
<s:SolidColor color="blue" />
</s:fill>
</s:Rect>
</s:BorderContainer>
</s:Application>
謝謝 - 這很有道理。我認爲這是不可能的,但是如果有一種方法你可能會知道:有沒有辦法讓一個rollOver或一個mouseOver事件觸發當前在頂部和後面的對象?或者,也許可以獲得鼠標當前位於其上的所有對象的列表,並檢查後面的對象是否是列表的一部分?這將使執行這件事變得輕而易舉。再次感謝! F。 – 2011-04-25 03:20:13