Avatar

Level 3

You could load that info from an XML file as described below. I took this from the doc.

To further externalize configuration, you can pass the endpoint URL value to the client at runtime. One way to do this is by reading a configuration file with an HTTPService component at application startup. The configuration file includes the information to programmatically create a channel set at runtime. You can use E4X syntax to get information from the configuration file.

The following MXML application shows this configuration file technique:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    applicationComplete="configSrv.send()">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.messaging.channels.AMFChannel;
    import mx.messaging.ChannelSet;
    import mx.rpc.events.ResultEvent;
    private var channelSet:ChannelSet;
    private function configResultHandler(event:ResultEvent):void
    {
        var xml:XML = event.result as XML;
        var amfEndpoint:String = "" + xml..channel.(@id=="amf").@endpoint;
        if (amfEndpoint == "")
        {
            Alert.show("amf channel not configured", "Error");
        }
        else
        {
            channelSet = new ChannelSet();
            var channel:AMFChannel = new AMFChannel("my-amf", amfEndpoint);
            channelSet.addChannel(channel);
            ro.channelSet = channelSet;
            ro.getProducts();
        }
    }
    ]]>
    </mx:Script>
    <mx:HTTPService id="configSrv" url="config.xml" resultFormat="e4x" result="configResultHandler(event)"/>
    <mx:RemoteObject id="ro" destination="product"/>
    <mx:DataGrid dataProvider="{ro.getProducts.lastResult}" width="100%" height="100%"/>
</mx:Application>

The MXML application reads the following configuration file:

<?xml version="1.0" encoding="utf-8"?>
<config>
    <channels>
        <channel id="amf" endpoint="http://localhost:8400/lcds-samples/messagebroker/amf"/>
    </channels>
</config>