1 Reply Latest reply on Jul 29, 2011 1:55 PM by Flex harUI

    MouseEvent and preventDefault()

    Swiffmaz Level 1

      It seems i am not allowed to use preventDefault() for my own use. The type MouseEvent.CLICK is not cancelable and preventDefault() won't set isDefaultPrevented() to true. So the only option i have is to use stopPropagation()? Therefore the following code will never work as expected (only one handler should care about the event)?

       

       

      <?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">
      
           <fx:Script>
                <![CDATA[
                     protected function item_clickHandler(event:MouseEvent):void
                     {
                          if (event.isDefaultPrevented()) return;
                          event.preventDefault();
                          // Handle event
                     }
      
                     protected function info_clickHandler(event:MouseEvent):void
                     {
                          if (event.isDefaultPrevented()) return;
                          event.preventDefault();
                          // Handle event
                     }
      
                     protected function price_clickHandler(event:MouseEvent):void
                     {
                          if (event.isDefaultPrevented()) return;
                          event.preventDefault();
                          // Handle event
                     }
      
                ]]>
           </fx:Script>
      
           <s:Group id="item" click="item_clickHandler(event)">
                <s:Label id="info" text="Info" click="info_clickHandler(event)" />
                <s:Image />
                <s:Label />
                <s:Label id="price" text="Price" click="price_clickHandler(event)" />
           </s:Group>
           
      </s:Application>