您好 我有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()
答案 0 :(得分: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>