我是Flex新手,無法理解事件。我認爲事件是我想要用於我的情況。我有2個組件,addUser.mxml
和listUsers.mxml
。我從我的主應用程序中的ViewStack訪問這些。當我加載listUsers.mxml
時,它通過HTTPService調用顯示數據網格中當前用戶的列表。當我使用addUser.mxml
上的表單添加用戶時,我想在返回到該視圖以顯示新用戶時刷新listUsers.mxml
中的數據網格。我用addEventListener
和dispatchEvent
嘗試了幾個不同的東西,但似乎無法讓它工作。有人可以用這個邏輯幫助我嗎?從動作更新外部Flex組件
-
評論的示例代碼,我解析了非相對的東西。
的adduser這個樣子的:
<mx:HTTPService id="httpService"
url="{'http://someurl.com'}"
useProxy="false"
method="POST"
fault="faultHandler()"
result="resultHandler(event)"
/>
public function addUser():void{
if(validateForm()){
params = {};
params['action'] = 'adduser';
params['firstName'] = firstName.text;
params['lastName'] = lastName.text;
params['email'] = email.text;
params['isActive'] = isActive.selected;
httpService.cancel();
httpService.addEventListener("result", addUserResult);
httpService.send(params);
}
}
public function addUserResult(event:ResultEvent):void{
var result:Object = event.result;
//reset fields if add user was successful
if(result.returnXML.action=='adduser'){
var m:String = result.returnXML.message.toString();
if(result.returnXML.status=='fail'){
Alert.show(m, null, Alert.OK, null, null, Application.application.IconError);
}
if(result.returnXML.status=='success'){
firstName.text = "";
lastName.text = "";
email.text = "";
isActive.selected = true;
Alert.show(m, null, Alert.OK, null, null, Application.application.IconSuccess);
}
}
}
<mx:Button id="addButton" label="Add" click="addUser();" />
listUsers看起來是這樣的:
<mx:HTTPService id="httpListService"
url="{'http://someurl.com'}"
useProxy="false"
method="POST"
fault="faultHandler()"
result="resultHandler(event)"
/>
<mx:DataGrid id="dgUsers"
itemClick="dgClickEvent(event);"
width="85%"
maxHeight="500"
>
<mx:columns>
<mx:DataGridColumn headerText="First Name" dataField="fn" />
<mx:DataGridColumn headerText="Last Name" dataField="ln" />
<mx:DataGridColumn headerText="Email" dataField="email" />
<mx:DataGridColumn headerText="Active" dataField="active" />
</mx:columns>
</mx:DataGrid>
你可以張貼一些代碼?很難知道如何幫助你解決具體的問題。 – bedwyr 2010-04-07 02:16:22
我在上面添加了一些代碼,謝謝! – Scott 2010-04-07 13:29:57