2015-08-21 62 views
0

我試圖聽Rect上的單擊事件(擴展圖形元素),但我知道這是不可能的。那麼我怎麼能做出一個可以點擊的Rect?如何檢測圖形元素上的單擊事件

示例代碼:

<s:Group width="100" height="100"> 
    <s:Rect width="10 height="10> 
     <s:fill> 
      <s:SolidColorFill color="red"/> 
     </s:fill> 
    </s:Rect> 
</s:Group> 

回答

1

不能在<s:Rect>添加click事件。要獲得結果,您需要添加額外的<s:Group>

你可以用這種方式實現。

<s:Group width="100" height="100" left="150" top="150" > 
      <s:Group width="10" height="10" click="onClick(event)"> 
      <s:Rect width="100%" height="100%"> 
       <s:fill> 
        <s:SolidColor color="red"/> 
       </s:fill> 
      </s:Rect> 
       </s:Group> 
     </s:Group> 

<fx:Script> 
     <![CDATA[ 

       protected function onClick(event:MouseEvent):void 
       { 
        // Add your code here. 
       } 
     ]]> 
    </fx:Script> 

希望它能解決您的問題。

+0

無論我點擊它有點擊事件。是否有一個屬性,以便僅在圖形圖層上而不是在透明區域上單擊事件? –

相關問題