• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Binding web service results (XML) to components

Explorer ,
Jun 27, 2012 Jun 27, 2012

Copy link to clipboard

Copied

I am new to Flex/Flash Builder (have been CFer for years). I am trying to learn the tool/syntax, etc. to utilize Flash Builder to build a Flex application for AIR. So here is my newbie question...

I have a simple webservice that I wrote in a CFC. It appears to be working correctly as I can hit it and display the lastresult as a string with no problem. The result that comes back is an XML result. What I would like to do is to access specific pieces of the XML to render in a component, say a label.

Here is my XML result...

<users>

     <user id="123">

          <name>Company Buyer</name>

          <email>someone@somecompany.com</email>

          <loggedin>Y</loggedin>

     </user           

</users>

Here is my FB code...

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

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                       xmlns:s="library://ns.adobe.com/flex/spark"

                       xmlns:mx="library://ns.adobe.com/flex/mx"

                       xmlns:users="services.users.*">

    <fx:Script>

        <![CDATA[

            import mx.collections.ArrayCollection;

            import mx.controls.Alert;

            import mx.rpc.events.FaultEvent;

            import mx.rpc.events.ResultEvent;

            // Variable decalrations --------------------------------------

            [Bindable]

            private var userInfo:ArrayCollection;

            protected function button_clickHandler(event:MouseEvent):void

            {

                loginUserResult.token = users.loginUser(argUsernameTextInput.text,argPasswordTextInput.text);

            }

            protected function users_resultHandler(event:ResultEvent):void

            {

                userInfo = event.result as ArrayCollection;

            }

            protected function users_faultHandler(event:FaultEvent):void

            {

                Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail);

            }

        ]]>

    </fx:Script>

    <!-- Declarations -->

    <fx:Declarations>

        <s:CallResponder id="loginUserResult"/>

        <users:Users id="users"

                     fault="users_faultHandler(event)"

                     showBusyCursor="true"

                     result="users_resultHandler(event)"/>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>

    <!-- UI Components -->

    <mx:Form defaultButton="{button}" id="loginForm" dropShadowVisible="false">

        <mx:FormItem label="User Name">

            <s:TextInput id="argUsernameTextInput"/>

        </mx:FormItem>

        <mx:FormItem label="Password">

            <s:TextInput id="argPasswordTextInput"/>

        </mx:FormItem>

        <s:Button label="LoginUser" id="button" click="button_clickHandler(event)"/>

    </mx:Form>

    <mx:Form x="0" y="149">

        <mx:FormItem label="LoginUser">

        </mx:FormItem>

        <s:TextArea id="loginUserTextInput" text="{loginUserResult.lastResult as String}" height="191" width="428"/>

    </mx:Form>

</s:WindowedApplication>

I searched the web to try to find a simple tutorial and could not find anything. So I am probably missing something simple. Any thoughts?

~Clay

Views

608

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 29, 2012 Jun 29, 2012

Copy link to clipboard

Copied

LATEST

Figured it out. Instead of returning XML, I changed my CFC to return a struct and it was much easier to handle.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines