我试图捕获一个事件,但我不能。 请看这里: http://www.pata.ro/FlexTest/ 蓝色的矩形是父母,其他两个是孩子。 如果我翻转一个孩子(红色或绿色),我仍然在蓝色之上(对于蓝色的,RollOut不会被解雇)。我把绿色的矩形做成了一个透明的,所以你可以看到它已经覆盖了红色。 当我把光标放在绿色的那个上面的时候,我得到了BlueRollOver,GreenRollOver,RedRollOut。 我试图做的是获得红色的RollOver,即使它在绿色之下。就像父母抓住RollOver一样,即使我在其中一个孩子身上。或相反亦然。 那么,如何将事件传播到鼠标悬停的元素下?Flex事件传播
感谢
娄你有我的代码。 事件监听器是在MXML中声明的,所以我重写了那些红色的矩形,所以我可以添加useCapture参数。如果我将useCapture设置为TRUE,那么只要有鼠标,红色矩形就不会捕获任何事件。如果我将它设置为false,它会像以前一样工作。那么,我该如何使用这个论点呢?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
applicationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function init():void
{
gRed.addEventListener(MouseEvent.ROLL_OVER,RedRollOver,true);
gRed.addEventListener(MouseEvent.ROLL_OUT,RedRollOut,true);
}
private function BlueRollOver(ev:Event):void
{
idBlue.text="RollOver";
}
private function BlueRollOut(ev:Event):void
{
idBlue.text="RollOut";
}
private function RedRollOver(ev:Event):void
{
idRed.text="RollOver";
}
private function RedRollOut(ev:Event):void
{
idRed.text="RollOut";
}
private function GreenRollOver(ev:Event):void
{
idGreen.text="RollOver";
}
private function GreenRollOut(ev:Event):void
{
idGreen.text="RollOut";
}
]]>
</fx:Script>
<s:Group id="gBlue" x="114" y="94" width="404" height="301" rollOver="BlueRollOver(event)" rollOut="BlueRollOut(event)">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#0000CC"/>
</s:fill>
</s:Rect>
<s:Group id="gRed" x="140" y="101" width="230" height="114">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#EE0000"/>
</s:fill>
</s:Rect>
</s:Group>
<s:Group id="gGreen" x="39" y="20" width="200" height="200" rollOver="GreenRollOver(event)" rollOut="GreenRollOut(event)">
<s:Rect width="100%" height="100%" alpha="0.6">
<s:fill>
<s:SolidColor color="#00EE00"/>
</s:fill>
</s:Rect>
</s:Group>
</s:Group>
<s:Label x="535" y="94" text="Blue" color="#0000CC" width="149" id="idBlue"/>
<s:Label x="535" y="114" text="Red" color="#EE0000" width="173" id="idRed"/>
<s:Label x="535" y="137" text="Green" color="#00EE00" width="173" id="idGreen"/>
</s:Application>
对不起。我已阅读并测试useCapture,但它不起作用。它用于别的东西,而不是在兄弟之间传播事件。 – Adrian 2010-04-21 14:21:33