0

During development I have to test using several different hosts. It is a pain to have to change the IP address everywhere I use navigateToURL or in an mx:HTTPService.

I would like to set a var with the IP...

public var hostIP:String = "192.168.1.100";

Then later I instead of doing...

navigateToURL(new URLRequest('http://192.161.1.100/JudgesRegistration.html?email='+email+'&password='+password),'_self')

I would like to do something like...

navigateToURL(new URLRequest('http://'+hostIP+'/JudgesRegistration.html?email='+email+'&password='+password),'_self')

Then I would only have to change the IP assigned to hostIP instead of throughout the project. Unfortunately I can't figure out how to imbed the var in the URL string. Is this even possible?

Here is what my HTTPService looks like...

<mx:HTTPService 
    id="emailPasswordService"
    method="POST"
    url="http://192.168.1.100/chaos/emailPassword?output=xml"
    makeObjectsBindable="true"
    result="emailPasswordSuccess(event)"
    fault="httpServiceFaultHandler(event)"
    showBusyCursor="true"
    resultFormat="e4x">
</mx:HTTPService>

Thanks,

John

user278859
  • 10,379
  • 12
  • 51
  • 74
  • 1
    your URL is wrong: you need // after the http: Otherwise, I see no reason this shouldn't work. – bedwyr Dec 27 '11 at 03:55

2 Answers2

1

This should simply just work.

navigateToURL(new URLRequest('http://' + hostIP + '/JudgesRegistration.html?email=' + email + '&password=' + password),'_self')

Are you finding any errors?

Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
  • I'm sorry. I just tried it again in navigateToURL and it worked, but I am still not having success with the var in an HTTP:Service. URL="http://"+hostIP+"/blah/blah" will not build. I get "Element type "mx:HTTPService" must be followed by either attribute specifications, "." or "/>". Can I use the var in the HTTP:Service? – user278859 Dec 27 '11 at 04:18
  • I added an example HTTPService to my question.As in the navigateToURL, I am trying to replace the 192.168.1.100 with the var. – user278859 Dec 27 '11 at 04:37
  • Ok I got it. URL="http://{hostIP}/blah/blah" works! I also had to make hostIP [Bindable] – user278859 Dec 27 '11 at 05:03
1

I think that what you are looking for are static class constants. You can declare a class that has constants which are accessible everywhere in your project.

package <any location you want>
{
    public class HostInfos
    {
        // static constants
        public static const HOST_IP:String = "192.168.1.100";

        public function HostInfos() {}
    }
}

Once you have a class like that, you can call the HOST_IP constant anywhere and retrieve its value. Ex.:

navigateToURL(new URLRequest('http://' + HostInfos.HOST_IP + '/JudgesRegistration.html?email='+email+'&password='+password),'_self')
joelrobichaud
  • 665
  • 4
  • 19