1.21 gigawatts
1.21 gigawatts

Reputation: 17830

How to detect a click event on a Graphic Element

I'm trying to listen for a click event on a Rect (extends Graphic Element) but I know it is impossible. How then can I make a Rect that can be clicked on?

Example Code:

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

Upvotes: 0

Views: 67

Answers (1)

Randhir Kumar
Randhir Kumar

Reputation: 197

You can not add click event on <s:Rect>. To achieve the result you need to add extra <s:Group>.

you can implement in this way.

  <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>

Hope it solve your problem.

Upvotes: 1

Related Questions