Expand my Community achievements bar.

HTTPService Login system

Avatar

Level 1
Hi I was just wondering if any one could help me out with
this, i am trying to create a user login sytem using the
HTTPService that passes username & email to the server and
returns the users details, from which i can then log them into the
flex system. I have managed to set up the sending of the data and
returning of the user data into a data grid, however when i try to
extract just one element from the returned XML data i cant seem to
move down the nodes my xml is returned in this format ::

<rss>

<channel>

<title>UserLogin</title>

<item>

<id>1</id>

<userLevel>1</userLevel>

</item>

</channel>

</rss>



Im trying to pass the userlevel data into a actionScript
variable is there anyway to do this?





And here is my MXML file::

<?xml version="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
width="160"

horizontalAlign="center" cornerRadius="10"
borderStyle="solid" borderThickness="1"

backgroundColor="#c0c0c0" dropShadowEnabled="true" >

<mx:Script>

<![CDATA[

import mx.controls.Alert;

import mx.rpc.events.ResultEvent;

import mx.collections.ArrayCollection;

[Bindable]

private var loginData:ArrayCollection;



private function loginDataHandler(event:ResultEvent):void{

loginData = event.result.rss.channel.item;

}

]]>

</mx:Script>

<mx:HTTPService id="loginRequest" url="PHP/Login.php"
method="POST"

result="loginDataHandler(event)">

<mx:request>


<userName>{userName_txt.text}</userName><password>{password_txt.text}</password>

</mx:request>

</mx:HTTPService>

<mx:Label text="LOGIN"/>

<mx:TextInput id="userName_txt" width="140"
text="UserName"/>

<mx:TextInput width="140" id="password_txt"
text="Password" displayAsPassword="true"/>

<mx:Button label="Login" id="login_btn"
click="loginRequest.send()"/>

<mx:DataGrid id="loginAuth"
dataProvider="{loginRequest.lastResult.rss.channel.item}

" width="150" height="71">

</mx:DataGrid>

</mx:VBox>

If anyone can tell me how to pass variables from the returned
XML into actionsript that would be great as i can probably work it
out from there.

Absolutely any help or ideas would be great.

Thanks in advance

1 Reply

Avatar

Level 3
Hi,



By default the HttpService deserialize return xml as object.
Setting datagrid.dataprovider to an object won't work. It takes
array or arrayCollection.



loginRequest.lastResult.rss.channel.item is an object

<item>

<id>1</id>

<userLevel>1</userLevel>

</item>



if you want to show it on datagrid, you can do this

dataProvider="{[loginRequest.lastResult.rss.channel.item]}

instead of

dataProvider="{loginRequest.lastResult.rss.channel.item}







William Chan





From AS doc

resultFormat property



resultFormat:String [read-write]

Value that indicates how you want to deserialize the result
returned by the HTTP call. The value for this is based on the
following:



Whether you are returning XML or name/value pairs.

How you want to access the results; you can access results as
an object, text, or XML.

The default value is object. The following values are
permitted:

object The value returned is XML and is parsed as a tree of
ActionScript objects. This is the default