Apache flex 在文本区域外单击时禁用文本区域
我有一个文本区域和一个按钮-我希望当用户单击应用程序窗口中除发送按钮以外的任何位置时,该按钮消失Apache flex 在文本区域外单击时禁用文本区域,apache-flex,events,Apache Flex,Events,我有一个文本区域和一个按钮-我希望当用户单击应用程序窗口中除发送按钮以外的任何位置时,该按钮消失 <mx:Button x="306" y="168" label="Button" id="btn" click="Alert.show('Button clicked')"/> <mx:TextArea x="138" y="146" focusOut="btn.visible=false" focusIn="btn.visible=true"/> 当TextArea使用
<mx:Button x="306" y="168" label="Button" id="btn" click="Alert.show('Button clicked')"/>
<mx:TextArea x="138" y="146" focusOut="btn.visible=false" focusIn="btn.visible=true"/>
当TextArea使用focusOut事件失去焦点时,我尝试调用btn.visible=false-如果我单击应用程序中的任何位置,它都会工作,但当我单击按钮时,它也会工作-TextArea focusOut事件会先处理,然后单击按钮-有人能帮我吗
谢谢 我之前说过稍后使用call,但在测试时它不起作用,很抱歉浪费了大家的时间。相反,你需要像这样使用焦点管理器:我测试了这个,它看起来很可靠
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.FocusManager; //pull in the manager
private function onFocusOut(event:FocusEvent):void{
if(getFocus() != null){ //in case focus goes outside the flash player
if(getFocus().name == "btn"){ //the focus went to the item with the ID "btn"
return; //do nothing, let the click handler work
}else{ //any other item gets focus
btn.visible=false; //disappear
}
}
}
private function clickHandler():void{ // made it it's own function so do more than just alert
Alert.show('Button clicked');
btn.visible=false;
}
]]>
</mx:Script>
<mx:Button x="306" y="168" label="Button" id="btn" click="clickHandler();"/>
<mx:TextArea x="138" y="146" focusOut="onFocusOut(event)" focusIn="btn.visible=true"/>
</mx:Application>
您是否试图覆盖默认的focusOut处理程序?那不行
private function setBtnNotVisible():void
{
btn.visible=false;
}
override protected function focusOutHandler(event:FocusEvent):void
{
callLater(setBtnNotVisible);
}
编写自己的事件处理程序也是如此
private function setBtnNotVisible():void
{
btn.visible=false;
}
private function focusOutHandler2(event:FocusEvent):void
{
callLater(setBtnNotVisible);
}
-----------完整代码---------
尝试在文本区域内单击,然后单击按钮,我无法捕捉警报
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function onFocusOut(event:FocusEvent):void{
callLater(
function ():void{
btn.visible=false;
}
)
}
]]>
</mx:Script>
<mx:Button x="306" y="168" label="Button" id="btn" click="Alert.show('Button clicked')"/>
<mx:TextArea x="138" y="146" focusOut="onFocusOut(event)" focusIn="btn.visible=true"/>
</mx:Application>
我当时正在从头开始键入它,当我查看它时,我需要稍后在调用中添加函数。更新后的示例应该可以使用。嗯,不可以,抱歉,这也不起作用。。我正在更新下面的代码…我拿了你的代码并玩了它。我个人不知道为什么后来的电话不起作用,但我对flex还是相当陌生。这段新代码已经过测试,运行良好。希望它对您有效,以便您可以继续您的项目:-