如何使用动作脚本3.0在另一个函数中调用函数 在这里,我使用WSDL Web服务并在我的数据网格中获取数据。我想把这些数据放到我的数据库表中。
我在与WebService关联的Button click事件上调用了Follow函数。
private function Login():void {
// Get Data from WebService and fill datagrid when you fist invoke the application
SignIn1Result2.token = vtrServices.SignIn1(txtUserName.text, txtPassword.text);
stmt.sqlConnection = this.isDbConnected(conn);
func:addEventListener(SQLEvent.OPEN,insertContact);
/* insertContact(SignIn1Result2.lastResult.UserId,SignIn1Result2.lastResult.UserName,SignIn1Result2.lastResult.ContactName,SignIn1Result2.lastResult.Password,SignIn1Result2.lastResult.Salt); */
}
我的WebService定义
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:WebService
id="ws"
wsdl="http://localhost:2690/vtrServices.asmx?wsdl">
<mx:operation
name="GetEmployees"
resultFormat="object"
result="Login()"
/>
</mx:WebService>
<vtrservices:VtrServices id="vtrServices"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
<s:CallResponder id="SignIn1Result2"/>
</fx:Declarations>
我的控件
<mx:Panel x="41.5" y="66" width="714.5" height="237" layout="absolute" title="ASP.NET WebService + Flex Demonstration">
<mx:HBox height="95%" width="95%" horizontalCenter="0" verticalCenter="0">
<mx:DataGrid id="datagrid" width="499" height="100%"
dataProvider="{SignIn1Result2.lastResult}">
<mx:columns>
<mx:DataGridColumn headerText="User Id" dataField="UserId"/>
<mx:DataGridColumn headerText="UserName" dataField="UserName"/>
<mx:DataGridColumn headerText="ContactName" dataField="ContactName"/>
<mx:DataGridColumn headerText="Password" dataField="Password"/>
<mx:DataGridColumn headerText="Salt" dataField="Salt"/>
</mx:columns>
</mx:DataGrid>
<mx:Form x="608" y="74" width="100%" height="100%" borderStyle="solid" id="UserLogin">
<mx:FormItem label="UserName">
<mx:TextInput width="106" id="txtUserName"/>
</mx:FormItem>
<mx:FormItem label="Password">
<mx:TextInput width="106"
displayAsPassword="true"
id="txtPassword"/>
</mx:FormItem>
<mx:FormItem width="156" horizontalAlign="right">
<mx:Button label="Login" id="btnLogin" click="Login();"/>
</mx:FormItem>
</mx:Form>
</mx:HBox>
</mx:Panel>
这是以下函数,应该在Login()函数成功后调用,或者我可以在Login()函数中说明
private function insertContact(UserId:String, UserName:String,ContactName:String, Password:String, Salt:String):void
{
stmt.sqlConnection = this.isDbConnected(conn);
stmt.text = "INSERT INTO TblUsers (UserId, UserName, ContactName ,Password, Salt) VALUES('"+SignIn1Result2.lastResult.UserId+"','"+SignIn1Result2.lastResult.UserName+"','"+SignIn1Result2.lastResult.ContactName+"','"+SignIn1Result2.lastResult.Password+"','"+SignIn1Result2.lastResult.Salt+"');";
Alert.show("Contact Has been Saved");
stmt.execute();
}
我已将以下内容绑定
[Bindable]
public var conn:SQLConnection = new SQLConnection();
[Bindable]
private var stmt:SQLStatement = new SQLStatement();
// ArrayCollection used as a data provider for the datagrid. It has to be bindable so that data in datagrid changes automatically when we change the ArrayCollection
[Bindable]
private var contactList:ArrayCollection = new ArrayCollection();
InsertContact()我想在Login()函数执行成功中调用的函数
答案 0 :(得分:0)
在函数中调用函数就像其他脚本语言一样但在这里您必须仔细观察要调用它们的事件。
我明白了,我发现了我正在做的错误。
正如我所说,我想调用WebService函数的成功函数
这里的函数应该在webService Call的Result Event上调用。
所以我刚刚将结果事件添加到我的FlexService应用程序的WebService块并根据它更改了Web服务定义
<mx:WebService
id="ws"
wsdl="http://localhost:2690/vtrServices.asmx?wsdl">
</mx:WebService>
<vtrservices:VtrServices id="vtrServices"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"
result="vtrServices_resultHandler(event)"/>
<s:CallResponder id="SignIn1Result2"/>
然后我在结果事件中使用了数据提供者及其“LastResult”属性 我希望执行的功能是
private function insertContact(UserId:String, UserName:String,ContactName:String, Password:String):void
{
stmt.sqlConnection = this.isDbConnected(conn);
stmt.text = "INSERT INTO TblUsers (UserId, UserName, ContactName ,Password) VALUES('"+UserId+"','"+UserName+"','"+ContactName+"','"+Password+"');";
Alert.show("Contact Has been Saved");
stmt.execute();
}
protected function vtrServices_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
Alert.show(SignIn1Result2.lastResult[0].UserName);
insertContact(SignIn1Result2.lastResult[0].UserId,SignIn1Result2.lastResult[0].UserName,SignIn1Result2.lastResult[0].ContactName,SignIn1Result2.lastResult[0].Password);
lblWelcome.text = "Welcome"
lblName.text = SignIn1Result2.lastResult[0].ContactName;
}
这里[0]是我的索引编号
谢谢