Well after a few hours of testing and changing the logic, it seems like that the assignment of the endpoint must happen before initializing the _serviceControl. I was trying to implement my logic using states which was buggy. However, when i moved the call to the setter on a new view (loginView) everything worked like a charm. From the looks of it, makes a direct call to the service and it is executed before the app is even displayed.
As a result, the solution for changing dynamically the server your gateway is located, is as follows:
Markers.as (or whatever you call it), changed From
protected override function preInitializeService():void
{
super.preInitializeService();
super._serviceControl.endpoint = "http://www.mydomain.com/gateway.php";
}
To
public var targetServer:String="";
protected override function preInitializeService():void
{
super.preInitializeService();
super._serviceControl.endpoint = "http://www.mydomain.com/gateway.php";
}
public function setTargetServer(s:String):void
{
targetServer=s;
super._serviceControl.endpoint = targetServer;
//trace(s+" targeted");
preInitializeService();
}
And in your login.mxml
var m:services.markersservice.MarkersService=new services.markersservice.MarkersService();
m.setTargetServer("http://www.mydomain.com/gateway.php");
navigator.pushView(HomeView);
I hope this will help more Flex developers.