2011-02-28 121 views
0

嗨 我有2個MXML文件中....問題與LinkBut​​ton的鼠標事件

CustComp.mxml

<mx:LinkButton id="linkbutton" label="ClickMe" click="onLinkClicked()" mouseOver="onMouseOver()" mouseOut="onMouseOut()" /> 

private function onLinkClicked():void{ 
dispatchEvent(new CustomEvent("onClick");} 
private function onMouseOver(event:CustomEvent):void{ 
dispatchEvent(new CustomEvent("onMouseOver");} 
private function onMouseOut(event:CustomEvent):void{ 
dispatchEvent(new CustomEvent("onMouseOut");} 

Main.mxml

var customComp:CustComp = new CustComp(); 
customComp.addEventListener(CustomEvent.MOUSE_CLICK1,onLinkClicked111); 
customComp.addEventListener(CustomEvent.MOUSE_OVER1,onMouseOver111); 
customComp.addEventListener(CustomEvent.MOUSE_OUT1,onMouseOut111); 

private function onLinkClicked111(event:CustomEvent):void{ 
trace("click event");} 
private function onMouseOver111(event:CustomEvent):void{ 
trace("mouse over event");} 
private function onMouseOut111(event:CustomEvent):void{ 
trace("mouse out event");} 

當我想提出一個鼠標懸停或鼠標懸停在組件中的鏈接按鈕上,事件將被分派到main.mxml,並且各個函數都會被完美調用。但是,當我單擊該按鈕時,onLinkClicked111()函數n被調用一次,並且onMouseOut111(),onMouseOver111()被重複調用,直到我使光標離開鏈接按鈕。 請幫我一下,我應該怎麼做以確保當我點擊時,只有onLinkclicked111()函數應該被調用,而不是mouseOver111()或mouseOut111()

回答

0

不知道你真的需要什麼,但這裏是簡單的例子

<?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" 
       creationComplete="application1_creationCompleteHandler(event)"> 


    <fx:Script> 
     <![CDATA[ 
      import mx.events.FlexEvent; 


      protected function application1_creationCompleteHandler(event:FlexEvent):void 
      { 
       addEventListener("onClick", onClickHandler); 
       addEventListener("onMouseOver", onMouseOverHandler); 
       addEventListener("onMouseOut", onMouseOutHandler); 
      }   


      private function onClickHandler(e:Event) : void 
      { 
       trace("onClick Handled"); 
      } 

      private function onMouseOverHandler(e:Event) : void 
      { 
       trace("onMouseOver Handled"); 
      } 

      private function onMouseOutHandler(e:Event) : void 
      { 
       trace("onMouseOut Handled"); 
      } 


      private function onLinkClicked():void 
      { 
       dispatchEvent(new Event("onClick")); 
      } 

      private function onMouseOver(event:MouseEvent):void 
      { 
       if (!event.buttonDown) 
       { 
       dispatchEvent(new Event("onMouseOver")); 
       } 
      } 
      private function onMouseOut(event:MouseEvent):void 
      { 
       if (!event.buttonDown) 
       { 
       dispatchEvent(new Event("onMouseOut")); 
       } 
      }  

    ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

    <mx:LinkButton id="linkbutton" label="ClickMe" click="onLinkClicked()" mouseOver="onMouseOver(event)" mouseOut="onMouseOut(event)" /> 

</s:Application>