在MXML的頁面中,使用了http返回參數中沒有定義的變量,并沒有顯示報錯信息,而是顯示了underfined。我用在text的顯示和輸入界面里了,如果用在tree或者其他的變量可能就報錯了。所以還是定義一個函數專門處理返回的參數能夠使程序更健壯吧!
近在看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>
posted on 2007-01-12 16:00
???MengChuChen 閱讀(219)
評論(0) 編輯 收藏