开发者

Issue with LinkButton mouse event

Hi I have 2 mxml files in which ....

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");}

开发者_JAVA百科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");}

When i am making a mouse over or mouse out on link button in component,the event is getting dispatched to main.mxml and respective functions are getting called perfectly.But When i click the button, onLinkClicked111() function is called once and onMouseOut111(), onMouseOver111() are repeatedly getting called until i make my cursor move away from link button. Please help me out as what should i do to make sure that when i click, only onLinkclicked111() function should get called not mouseOver111() or mouseOut111()


Not sure what you really need, but here is simplified example

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜