最近在看Flex的groups中发现有一个以前遇到的问题,但是没有意识到的问题。当我在一个函数中发出httpservice,然后加入一个事件的监听处理httpservice返回的值,后面如果还有代码回马上执行,并不会等处理完httpservice返回再进行。是我的代码有问题还是Flex本身就是这样的呢?刚刚看到Group里的一个贴子说在ActionScript中没有真正意义上的Blocking,用Alert,并且配合shoumodel模式来实现阻止用户继续和界面交互。这样对于我刚刚遇到的问题没有什么帮助,可以尝试在处理httpservice返回函数设置返回值,调用函数根据这个返回值进行下一步的操作。
There is no true blocking in ActionScript. Both alerts and modal pop-ups only
stop the user from interacting with the UI. All code continues to execute to
the end.
To do what you want, you need to have a two part approach, where you call the
confirmation dialog first, then, when that is dismissed, take the actual action.
Below is an example using an alert. In my application, is use a modal pop-up
so that I can have more control.
Tracy
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script><![CDATA[
private function doAction(sAction:String):Void
{
alert(sAction,
"Confirm Action",
mx.controls.Alert.YES|mx.controls.Alert.NO,
handleConfirm,
mx.controls.Alert.NO)
}//
private function handleConfirm(oEvent:Object):Void
{
switch(oEvent.detail)
{
case 1:
alert("The Action was Confirmed")
break;
case 2:
alert("The Action was Canceled")
break;
}//switch()
}//
]]></mx:Script>
<mx:Button label="Do Some Action" click="doAction('delete')"/>
</mx:Application>