3 Replies Latest reply on Jan 9, 2008 3:46 PM by nativeson

    Dynamic URLs for the mx:HTTPService component

    dmars87
      I am looking to make the url property of an mx:HTTPService component dynamic.

      <mx:HTTPService
      id="srvDivision"
      url=" http://prodserver/prod/get_division.jsp"
      useProxy="false" method="POST">
      </mx:HTTPService>

      I would just like to have an environment property or some other way where the value is not compiled into the code but derived at runtime. I am sure this quesiton has been asked before but I couldn't find a direct answer. I currently use a ResourceBundle (and properties file) but this is done at compile time. I would like to change the value of the " http://prodserver/prod" on the fly, depending on what environment I am working in...dev or test or whatever. I am not necessarily looking for the fastest way to do this, but the right way to do this. Is Data Services the way to go?
        • 1. Re: Dynamic URLs for the mx:HTTPService component
          stevetx2
          Here is an example...
          make a instance variable Bindable
          <mx:Script>
          <![CDATA[

          [Bindable]
          public var billToPath:String = "./bill.php";

          ]]>
          </mx:Script>

          <mx:HTTPService id="getBillName" url="{billToPath}" useProxy="false" method="POST" >
          <mx:request xmlns="">
          </mx:request>
          </mx:HTTPService>

          You could create a function to set the Path as well just make sure you create the class instance and then set the variable within the function.
          • 2. Re: Dynamic URLs for the mx:HTTPService component
            sakura102384
            How about when i wanted my HTTPService url to become dynamic that it gets from an external text file or xml file. Here is an exampl...

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:remoting="com.oreilly.
            programmingflex.rpc.*" layout="absolute" initialize="initializeHandler(event)">
            <mx:Script>
            <![CDATA[
            private function initializeHandler(event:Event):void {
            textService.send( );
            }
            private function resultHandler(event:Event):void {
            textArea.text = String(textService.lastResult);
            }
            ]]>
            </mx:Script>
            <!--<mx:HTTPService id="feedRequest" url="ip.txt" result="resultHandler(event)" useProxy="false"/>-->
            <mx:HTTPService id="textService" url=" http://123.136.72.41/mashupdemo/ip.xml" result="resultHandler(event)" />
            <mx:TextArea id="textArea" width="500"/>
            <mx:VideoDisplay id="vid" source="{textService.lastResult.subscribers.thevideo}" width="450" height="338" x="20" y="75" />
            </mx:Application>

            As you can see my HTTPService URL points to a file named ip.txt, the file includes my database URL where i will get my files to be played in my VideoDisplay. Is there anybody who can help me with this stuff. any reply would be very much appreciated. thanks!!!
            • 3. Dynamic URLs for the mx:HTTPService component
              nativeson
              If I am understanding correctly you could take the approach mentioned by stevetx2 and work it this way:

              On your app init function call an xml config file similar to a properties file found in a struts framework. (Create a file to have all the url's or other config information you might need)

              Create a bindable var as steve mentioned.

              On the config service result handler consume the config file and put it in an ArrayCollection.

              Then use databinding for your url.

              You can also do this in action script as well.

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="initializeHandler(event)">
              <mx:Script>
              <![CDATA[
              import mx.rpc.events.ResultEvent;
              import mx.collections.ArrayCollection;

              [Bindable]
              private var configData:ArrayCollection = new ArrayCollection();

              private function initializeHandler(event:Event):void {
              textService.send( );
              }
              private function resultHandler(event:ResultEvent):void {
              configData = event.result.myURLs;
              }
              ]]>
              </mx:Script>
              <mx:HTTPService id="feedRequest" url="{configData.thisUrl}" result="resultHandler(event)" useProxy="false"/>-->

              </mx:Application>

              This may be the idea you are looking for.