我正在尝试使用动作脚本3.0和php开发一个flex 4应用程序。 在按钮单击时,我想检查callRespoder是否从php函数接收到任何结果,但它不能像我想要的那样正常工作。它仅在我点击按钮两次时才有效。
flex应用程序代码:
<?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;
}
}
}
?>
答案 0 :(得分:1)
你的做法对我来说非常不合时宜。
首先,您似乎永远不会拨打任何电话。除非它封装在您未提供的Userlogin
代码中。通常你会做这样的事情:
<mx:HTTPService id="loginService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" result="onResult()"/>
在某些时候,你会这样做:
loginService.send();
调用您的后端代码。
在结果事件中,将结果存储在某处:
var results : Object;
public function onResult(event:ResultEvent):Void{
results = event.result;
}
然后在你的点击处理程序中,只需执行以下操作:
protected function button_click(event:MouseEvent):void
{
if(results )
{
navigateToURL(new URLRequest
('studentmenu.html'));
}
else
{
msg.text="Invalid Login";
}
}
当然,基于我对您的代码的有限理解,看起来您正在使用此Flex SWF作为登录表单,然后将用户发送到其他页面w / navigateToURL。这很不寻常;因为大多数Flex应用程序是自包含的。成功登录后,更改应用程序的状态或ViewStack的索引以加载其他视图会更常见;不要将用户重定向到其他页面。
答案 1 :(得分:0)
您应该只能将事件处理程序添加到CallResponder的结果属性中:
<s:CallResponder id="loginResult" result="myResultHandler(event)"/>
=瑞恩