Php 在Flex4中,如何使用动作脚本检查callResponder是否收到任何结果
我正在尝试使用ActionScript3.0和php开发一个Flex4应用程序。 在点击按钮时,我想检查callRespoder是否从php函数接收到任何结果,但它并没有像我所希望的那样实际工作。只有当我点击两次按钮时,它才会工作 flex应用程序代码:Php 在Flex4中,如何使用动作脚本检查callResponder是否收到任何结果,php,apache-flex,actionscript,Php,Apache Flex,Actionscript,我正在尝试使用ActionScript3.0和php开发一个Flex4应用程序。 在点击按钮时,我想检查callRespoder是否从php函数接收到任何结果,但它并没有像我所希望的那样实际工作。只有当我点击两次按钮时,它才会工作 flex应用程序代码: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xm
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="1010" height="620"
xmlns:userlogin="services.userlogin.*">
<fx:Style source="cssStyle/Style.css"/>
<fx:Script>
<![CDATA[
import flash.net.navigateToURL;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import valueObjects.LoginDataType;
protected function button_click(event:MouseEvent):void
{
loginResult.token =userlogin.login
(uname.text,password.text);
if(loginResult.lastResult!=null)
{
navigateToURL(new URLRequest
('studentmenu.html'));
}
else
{
msg.text="Invalid Login";
}
}
/* protected function msg_dataChangeHandler():void
{
if(msg.text=="")
{
Alert.show("Invalid Login"+msg.text);
}
else
{
Alert.show("Valid Login"+msg.text);
}
} */
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="loginResult"/>
<userlogin:Userlogin id="userlogin" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" />
</fx:Declarations>
<mx:Canvas borderColor="#003333" borderVisible="true" borderStyle="solid" width="1010" height="620">
<mx:Image x="27" y="6" width="52" height="52" source="images/Academia-left.jpg" click="navigateToURL(new URLRequest('http://www.academiadirect.com'))" buttonMode="true"/>
<mx:Image x="215" y="11" width="573" height="38" source="images/Academia-center.jpg" click="navigateToURL(new URLRequest('http://www.academiadirect.com'))" buttonMode="true"/>
<mx:Image x="828" y="10" width="170" height="52" source="images/Tamarind-Academia.gif" click="navigateToURL(new URLRequest('http://www.academiadirect.com'))" buttonMode="true"/>
<mx:Image x="0" y="117" width="532" height="498" source="images/Academia - Home.jpg" click="navigateToURL(new URLRequest('http://www.academiadirect.com'))" buttonMode="true"/>
<mx:Image x="650" y="128" width="30" height="26" source="images/Term Planning and Course Management.jpg"/>
<s:Label x="698" y="128" text="Term Planning and Course Management" styleName="lable"/>
<mx:Image x="650" y="168" width="30" height="26" source="images/Knowledge Repository Management.jpg"/>
<s:Label x="698" y="168" text="Knowledge Repository Management" styleName="lable"/>
<mx:Image x="650" y="208" width="30" height="26" source="images/Stakeholder Collaboration Management.jpg"/>
<s:Label x="698" y="208" text="Stakeholder Collaboration Management" styleName="lable"/>
<mx:Image x="650" y="248" width="30" height="26" source="images/Assessment and Evaluation Management.jpg"/>
<s:Label x="698" y="248" text="Assessment and Evaluation Management" styleName="lable"/>
<mx:Image x="650" y="288" width="30" height="26" source="images/Feedback and Quality Management.jpg"/>
<s:Label x="698" y="288" text="Feedback and Quality Management" styleName="lable"/>
<mx:Image x="650" y="328" width="30" height="26" source="images/Permissions Management.jpg"/>
<s:Label x="698" y="328" text="Permissions Management" styleName="lable"/>
<s:Label x="0" y="66" text="S t a y A h e a d" width="100%" height="28" styleName="NamePlate"/>
<mx:Label x="743" y="379" width="124" id="msg" visible="true"/>
<s:Panel x="652" y="399" width="314" height="163" title="Login">
<s:Label text="User Name:" styleName="lable" x="35" y="19"/><s:TextInput id="uname" styleName="textbox" x="141" y="19" />
<s:Label text="Password:" styleName="lable" x="35" y="48"/><s:TextInput id="password" styleName="textbox" x="141" y="48" displayAsPassword="true"/>
<s:Button label="Login" x="120" y="94" id="button" styleName="button" toolTip="Login" click="button_click(event);"/>
</s:Panel>
</mx:Canvas>
</s:Application>
PHP代码:
<?php
class userlogin
{
var $username = "root";
var $password = "";
var $server = "localhost";
var $databasename = "tamarind_academia";
public function userlogin()
{
$this->conn = mysqli_connect($this->server,$this->username,$this->password,$this->databasename);
//$this->throwExceptionOnError($this->conn);
}
public function login($username,$password)
{
$query = mysqli_prepare($this->conn, "SELECT user_id,fname,lname,instid,collid,locid,desigid FROM user_info where uname='".$username."' and pass='".$password."'");
//$this->throwExceptionOnError();
mysqli_stmt_execute($query);
//$this->throwExceptionOnError();
mysqli_stmt_bind_result($query, $row->user_id,$row->fname, $row->lname, $row->instid, $row->collid, $row->locid, $row->desigid);
if(mysqli_stmt_fetch($query))
{
return $row;
}
else
{
return null;
}
}
}
?>
你的方法对我来说非常不寻常
首先,您似乎从未进行过任何远程呼叫。除非它封装在您未提供的Userlogin
代码中。通常你会这样做:
<mx:HTTPService id="loginService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" result="onResult()"/>
protected function button_click(event:MouseEvent):void
{
if(results )
{
navigateToURL(new URLRequest
('studentmenu.html'));
}
else
{
msg.text="Invalid Login";
}
}
调用您的后端代码
在结果事件中,将结果存储在以下位置:
var results : Object;
public function onResult(event:ResultEvent):Void{
results = event.result;
}
然后在单击处理程序中,只需执行以下操作:
<mx:HTTPService id="loginService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" result="onResult()"/>
protected function button_click(event:MouseEvent):void
{
if(results )
{
navigateToURL(new URLRequest
('studentmenu.html'));
}
else
{
msg.text="Invalid Login";
}
}
当然,基于我对代码的有限理解,看起来您正在使用这个Flex SWF作为登录表单,然后将用户发送到另一个带有navigateToURL的页面。这是不寻常的;因为大多数Flex应用程序都是独立的。成功登录后,更常见的做法是更改应用程序的状态或ViewStack的索引以加载其他视图;不将用户重定向到其他页面。您应该能够将事件处理程序添加到CallResponder的result属性中:
<s:CallResponder id="loginResult" result="myResultHandler(event)"/>
=瑞安