2012-01-30 145 views
0

我跟着一個關於如何在flex中創建登錄系統的例子。此示例不適用於Flex移動項目,而是在瀏覽器中運行的桌面。據我所知,我可以使用相同的代碼,但具有不同的組件。我不斷收到錯誤。我的代碼在下面。用flex mobile登錄系統

用於連接和quering數據庫,併發送結果返回的XML

<?php 

echo "<?xml version="\"1.0\" ?>\n"; 

$con = mysql_connect("HOST","USER","PASS"); 
if (!$con) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db("DatabaseName here"); 

//Variables that I wil retrieve from the flex application 

$user = $_POST['user']; 
$pass = $_POST['pass']; 


//mySQL query 
$result = mysql_query("SELECT * FROM `brukere` WHERE 1"); 

//not logged in so it's false 
$loged = false; 

//Comparing the text i retrieved from the flex app and the rows in my database. 

while($row = mysql_fetch_assoc($result)) 
{ 
    if(strtolower($user) == strtolower($row['brukernavn']) && 
    strtolower($pass) == strtolower($row['passord'])) 
    { 
     $loged = true: 
     } 
} 

//so if loged is true, pass true in xml to my flex application. 
if($loged == true) 
echo "<status>true</status>"; 
else 
echo "<status>false</status>"; 
?> 

我在flex代碼的HTTPService

<fx:Declarations> 

    <mx:HTTPService id="loginService" result="onResult(event)" method="POST" url="URL TO THE PHP SCRIPT"> 

     <mx:request xmlns=""> 

      <user>{username.text}</user> 

      <pass>{pass.text}</pass> 

     </mx:request> 

    </mx:HTTPService> 
     </fx:Declarations> 

然後我的動作腳本的PHP代碼

<fx:Script> 
    <![CDATA[ 
     import mx.rpc.events.ResultEvent; 
     import mx.controls.Alert; 

     private function login():void 
     { 
      loginService.send();  
     } 

     private function onResult(e:ResultEvent):void 
     { 

      if(e.result.status == true) { 

       Alert.show("Succesful"); 

      } 

      else { 

       Alert.show("Wrong"); 
      } 
     } 
    ]]> 
</fx:Script> 

最後的GUI:

<s:VGroup includeIn="notLoggedIn" x="286" y="164" width="45%" height="200"> 
    <s:HGroup includeIn="notLoggedIn" width="100%" height="38" verticalAlign="middle"> 
     <s:Label width="30%" height="31" text="Brukernavn: " verticalAlign="middle"/> 
     <s:TextInput id="username" width="70%"/> 
    </s:HGroup> 
    <s:Spacer width="459" height="10"/> 
    <s:HGroup includeIn="notLoggedIn" width="100%" height="40" verticalAlign="middle"> 
     <s:Label width="30%" height="34" text="Passord:" verticalAlign="middle"/> 
     <s:TextInput id="pass" width="70%"/> 
    </s:HGroup> 
    <s:Spacer width="458" height="10"/> 
    <s:HGroup width="462" height="65"> 
     <s:Spacer width="70%" height="64"/> 
     <s:Button width="30%" label="Logg inn" click="login()"/> 
    </s:HGroup> 
</s:VGroup> 

這是當我調試應用程序的所有輸出:

[SWF] AKTIVe.swf - 4,192,242 bytes after decompression 
ReferenceError: Error #1069: Property status not found on String and there is no default value. 
at Views::Login/onResult()[C:\Users\Tobias\Documents\bacheloroppgave\workspace\src\Views\Login.mxml:54] 
at Views::Login/__loginService_result()[C:\Users\Tobias\Documents\bacheloroppgave\workspace\src\Views\Login.mxml:13] 
at flash.events::EventDispatcher/dispatchEventFunction() 
at flash.events::EventDispatcher/dispatchEvent() 
at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:993] 
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318] 
at mx.rpc::Responder/result()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\Responder.as:56] 
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84] 
at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451] 
at flash.events::EventDispatcher/dispatchEventFunction() 
at flash.events::EventDispatcher/dispatchEvent() 
at flash.net::URLLoader/onComplete() 

我首先想到的是,我不能在我的手機Flex應用程序使用<mx:HTTPService>和其他基於MX服務。有人知道我應該找什麼嗎?

對不起,我長的帖子,但ATLEAST非正式足夠:)

在此先感謝

+0

哪個代碼是上Login.mxml的54行? – JeffryHouser 2012-01-30 13:51:32

+0

if(e.result.status == true) – 2012-01-30 13:59:33

+1

我猜e.result是null;這就是爲什麼你會得到錯誤。您無法訪問空對象(e.result)上的屬性(AKA狀態)。然而,至於爲什麼這不是回報什麼是未知的。 – JeffryHouser 2012-01-30 14:55:21

回答