【发布时间】:2014-04-22 07:53:10
【问题描述】:
如何使用动作脚本 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() 函数执行成功内调用的函数
【问题讨论】:
标签: actionscript-3 apache-flex flex4 adobe flex3