LinkBut​​ton 鼠标事件问题

发布于 2024-10-19 15:19:59 字数 1289 浏览 0 评论 0原文

你好 我有 2 个 mxml 文件,其中 ....

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() 函数会被调用一次,并且 onMouseOut111() 和 onMouseOver111() 会被重复调用,直到我使光标从链接按钮上移开。 请帮助我,我应该做什么来确保当我单击时,只调用 onLinkclicked111() 函数而不是 mouseOver111() 或 mouseOut111()

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百合的盛世恋 2024-10-26 15:19:59

不确定您真正需要什么,但这是简化的示例

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文