开发者

in flex 4 using action script how to check whether callResponder receive any result or not

开发者 https://www.devze.com 2023-01-07 08:15 出处:网络
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 thecallRespoder receive any result or not from php function ,but it\'s

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.

flex Application code:

<?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 code:

<?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;
            }
    }
}
?>


Your approach is highly unusal to me.

First, it appears that you never make any remote calls. Unless it is encapsulated in the Userlogin code which you did not provide. Normally you would do something like this:

<mx:HTTPService id="loginService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" result="onResult()"/>

Than at some point, you'll do:

loginService.send();

to call your backend code.

In your result event, store the results somewhere:

var results : Object;    
public function onResult(event:ResultEvent):Void{
 results = event.result;
}

Then in your click handler, just do something like this:

        protected function button_click(event:MouseEvent):void
        {
            if(results )
            {
                navigateToURL(new URLRequest 
                                           ('studentmenu.html'));
            }
            else
            {
                msg.text="Invalid Login";                   
            }               
        }   

OF course, based on my limited understanding of your code, it looks like you're using this Flex SWF as a login form and then sending the user to some other page w/ navigateToURL. This is unusual; as most Flex apps are self contained. After a successful login the it would be more common to change the application's state or the index of a ViewStack to load other views; not redirect the user to some other page.


You should be able to just add an event handler to the result property of the CallResponder:

<s:CallResponder id="loginResult" result="myResultHandler(event)"/>

=Ryan

0

精彩评论

暂无评论...
验证码 换一张
取 消