4 Replies Latest reply on Jun 10, 2007 12:46 PM by leeng

    convert XML obj to text for a URLRequest argument

    leeng
      Hello,

      I'm new to Flex builder 2 and I am stuck doing something that I know is very basic but I am still on a learning curve (I'm a php procedural programmer, so I know OOP but haven't worked with it on a day to day basis)

      I have an XML file that one of the nodes contains a link to the help docs and there are different types of help docs.

      I have this setup:

      <mx:VBox label="Help Information">
      <mx:Label text="Help Line: {dgroomRequest.selectedItem.help.hphone}" fontSize="12"/>
      <mx:Label text="Links to Docs" textAlign="left" fontWeight="bold" fontSize="12" textDecoration="underline"/>
      <mx:Repeater id="helpdocsrepeater" dataProvider="{dgroomRequest.selectedItem.help.docs}">
      <mx:LinkButton label="{helpdocsrepeater.currentItem.@type}" click="navigateToURL(new
      URLRequest({helpdocsrepeater.currentItem}), '_blank')"/>
      </mx:Repeater>
      </mx:VBox>

      The problem I have is getting the URLRequest to recognize the databinding which points to the html link in the XML file. Everything else works but this part.

      I was thinking that the databinding was an obj so I thought about using toString() or wrapping it with String() to convert it but it doesn't seem to work.

      I appreciate any help or pointers.

      Thanks,
      Hoyt
        • 1. Re: convert XML obj to text for a URLRequest argument
          jinx82002 Level 1
          leeng,
          Not 100% sure this will work inline while the repeater item is laying out controls. But the way I handle stuff like this is in the linkbutton click, I would have just click="getPage(event)" or whatever you want to call that function.

          In the getPage(event:Event) i would trace out and make sure you have the correct link with trace(event.currentTarget.getRepeaterItem().@link); or whatever the path is to the correct url and from there build the new url request, and then navigateToURL() etc Let me know if that doesn't help you, I'll try to get you an example.
          • 2. Re: convert XML obj to text for a URLRequest argument
            leeng Level 1
            Thanks jinx82002!

            Yout answer makes sense, If you have an example that would be great. I'm just starting to pick up action script but it's a lot different from php, so any examples would be helpful. I'll give it a try tonight. Thanks again.

            be well,
            Hoyt
            • 3. Re: convert XML obj to text for a URLRequest argument
              jinx82002 Level 1
              Hey leeng,
              Sorry for the delay, had a rough week. But here's a quick dirty sample I whipped up for you. Although you may be using different components, it should still show you what needs to be done. This is how I'd do it:

              My test xml is:
              <content>
              <item label="Test one label">
              <link><![CDATA[ http://www.amazon.com/books
              <labelTwo>second label test</labelTwo>
              </item>
              <item label="Test two label">
              <link><![CDATA[ http://www.adobe.com
              <labelTwo>second label test</labelTwo>
              </item>
              </content>

              And my quick little app is:
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
              <mx:Script>
              <![CDATA[
              import mx.controls.Alert;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;
              import flash.net.URLRequest;

              private var request:URLRequest = new URLRequest();
              [Bindable]
              private var xml:XML = new XML();

              private function init():void{
              service.send();
              }
              private function doClick(event:Event):void{
              trace(event.currentTarget.getRepeaterItem().link);
              var site:String = event.currentTarget.getRepeaterItem().link;
              request.url = site;
              navigateToURL(request,"_blank");
              }
              private function resultHandler(event:ResultEvent):void {
              xml = XML(event.result);
              //trace(xml);
              }
              private function faultHandler(event:FaultEvent):void {
              Alert.show (event.fault.message);
              }
              ]]>
              </mx:Script>

              <mx:HTTPService
              id="service"
              url="test.xml"
              resultFormat="e4x"
              result="resultHandler(event);"
              fault="faultHandler(event);" />

              <mx:VBox label="Help Information">
              <mx:Label text="Help Line: test" fontSize="12"/>
              <mx:Label text="Links to Docs" textAlign="left" fontWeight="bold" fontSize="12" textDecoration="underline"/>
              <mx:Repeater id="helpdocsrepeater" dataProvider="{xml.item}">
              <mx:LinkButton label="{helpdocsrepeater.currentItem.@label}" click="doClick(event)"/>
              </mx:Repeater>
              </mx:VBox>

              </mx:Application>

              I'll try and send you a zip of it so you can see it work, just check the trace. Let me know if this helped you out or needs more explaining.
              • 4. Re: convert XML obj to text for a URLRequest argument
                leeng Level 1
                Yes! I see how it all works now! Thanks, this definitely makes sense now that I see it in code.