6 Replies Latest reply on Oct 8, 2007 11:24 AM by camfieldaj

    Loading information from a web page into Flex

    andyd273
      I need to be able to import a username from the containing web page into my SWF file.
      I've tried different things using params and flashvars, but so far no luck.

      I've also tried doing it as xml but I get a wierd fault error that I don't know how to fix:
      [RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: https://www.scan.com/getUsername.php"]. URL: getUsername.php"]
      at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::faultHandler()
      at mx.rpc::Responder/fault()
      at mx.rpc::AsyncRequest/fault()
      at private::DirectHTTPMessageResponder/errorHandler()
      at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/flash.net:URLLoader::redirectEvent()
      at [io]

      the XML that I'm trying to import looks like:
      <?xml version="1.0" encoding="utf-8"?>
      <members>
      <user><data>andyd273</data><label>username</label></user>
      </members>

      if anyone can help me figure out how to do it both ways that would be cool.
        • 1. Re: Loading information from a web page into Flex
          ab1301 Level 1
          Can you show us the code for the httpService you're using? When you type the url into your browser, does it return the xml properly? If its on a different domain than your swf, do you have a cross domain policy set up?
          • 2. Re: Loading information from a web page into Flex
            andyd273 Level 1
            Here's most of the important parts:

            <mx:Script>
            <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.controls.textClasses.TextRange;
            import mx.binding.utils.BindingUtils;
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;
            import mx.controls.*;
            import mx.managers.*;
            import mx.events.*;
            import flash.events.*;
            import flash.net.*;

            [Bindable]
            public var directories:Array = [ {label:"None", data:""},
            {label:"New Claim", data:"/new/"},
            {label:"Corrected Claim", data:"/corrected/"} ];

            [Bindable]
            private var userList:ArrayCollection;

            private function userDataHandleResult(event:ResultEvent):void
            {
            userList = event.result.members;
            }
            ]]>
            </mx:Script>

            <mx:HTTPService id="getUserNames" url="getUsername.php" />

            <mx:Canvas width="100%" height="304" bottom="20">
            <mx:DataGrid id="listFiles" left="0" top="50" bottom="126" right="0"
            allowMultipleSelection="true" verticalScrollPolicy="off"
            draggableColumns="false" resizableColumns="false" sortableColumns="false" enabled="true">
            <mx:columns>
            <mx:DataGridColumn headerText="File" dataField="name" wordWrap="true"/>
            <mx:DataGridColumn headerText="Size" dataField="size" width="75" textAlign="right"/>
            </mx:columns>
            </mx:DataGrid>
            <mx:TextArea height="108" right="10" left="10" bottom="10" id="txtFeedback" wordWrap="true" editable="false" enabled="true" valueCommit="txtFeedback.verticalScrollPosition=txtFeedback.maxVerticalScrollPosition"/>
            <mx:Label x="10" y="4" text="User:"/>
            <mx:ComboBox x="10" y="20" width="225" dataProvider="{getUserNames.lastResult.members.user}" id="cboUsername" creationComplete="getUserNames.send()"></mx:ComboBox>
            <mx:Label x="243" y="4" text="Directory:"/>
            <mx:ComboBox x="243" y="20" width="175" dataProvider="{directories}" id="cboDir"></mx:ComboBox>
            </mx:Canvas>

            The getUsername.php parses just fine in IE, looks just like any xml document.
            Here is where things get silly though...
            I have another file called getUserList.php that returns a table with all of the users in the database in the exact same format and it works just fine.
            So I played around with it some, and this is what I've got so far:
            There are two include files, $database and $session ($session includes $database).

            $database holds a class that lets you do stuff in the database,
            $session holds all of the session information, like username.

            So I took getUserList.php (which works) and replaced
            include("include/database.php");
            global $database;

            with

            include("include/session.php");
            global $database;

            and even though the output of the file is exactly the same, the SWF file throws that fault and refuses to load the user list.
            Oh, and to be on the safe side, I created a crossdomain.xml and uploaded it to my site, but it didn't help.
            • 3. Re: Loading information from a web page into Flex
              andyd273 Level 1
              but what I really want to know is how to load the information in from the webpage, if anyone knows if it is possible.
              • 4. Re: Loading information from a web page into Flex
                camfieldaj Level 1
                Maybe I'm missing something obvious, but where are you telling the datagrid where to get its data? ie: dataProvider="{userList}" in <mx:DataGrid id="listFiles" />
                • 5. Re: Loading information from a web page into Flex
                  andyd273 Level 1
                  no line numbers sadly, but it's about 6 from the bottom:

                  <mx:ComboBox x="10" y="20" width="225" dataProvider="{getUserNames.lastResult.members.user}" id="cboUsername" creationComplete="getUserNames.send()"></mx:ComboBox>

                  Like I said, it does work, but not when I include $session instead of $database... but that may be a lot bigger problem, and I'm willing to settle for the simplest solution...
                  • 6. Re: Loading information from a web page into Flex
                    camfieldaj Level 1
                    ok, if it's quick and dirty, I'm your guy:

                    <mx:HTTPService id="form1"
                    url=" http://servername/post.php"
                    method="POST"
                    useProxy="False"
                    resultFormat="text"
                    result="postResultHandler(event);"
                    fault="postFaultHandler(event);" >
                    <mx:request xmlns="" >
                    <vid>{vid_inp.text}</vid>
                    <VIPName>{vipname_inp.text}</VIPName>
                    <VIPAddress>{vipaddress_inp.text}</VIPAddress>
                    <ExternalAddress>{external_inp.text}</ExternalAddress>
                    <appName>{"vips"}</appName>
                    </mx:request>
                    </mx:HTTPService>

                    the HTTPService is launched by form1.send();

                    and in the postResultHandle function, set your combo box values, if you get anything back from the php script. :}