近在看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">
? ? ? ??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>