I am trying to developed one flex 4 appliction using action script 3.0 and php. In which on button click i want to check whether the callRespoder receive any result or not from php function ,but it's not working as actally as i want.It's work only on when i click on the button twice.
esnek Uygulama kodu:
<?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 kodu:
<?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;
}
}
}
?>