views:

27

answers:

1

Hi all,

So I know BlazeDS's standard MXML syntax for creating remote objects. Ex:

    <s:RemoteObject id="sim" destination="SimulationWebService" >
        <s:method name="getAvailableTargetNames" result="setTargetNames(event)" />
        <s:method name="getAvailableToolNames" result="setToolNames(event)" />
        <s:method name="getAvailableActionNames" result="setActionNames(event)" />
        <s:method name="simulate" result="resetFields(event)" />
    </s:RemoteObject>

But this isn't quite what I want to do. This forces me to create an instantiation of the class behind SimulationWebService as soon as the page loads, whereas I may want to do a variety of different things depending on user actions, including not create one at all. How do I create this same object from ActionScript?

A: 

I not sure if I understand correctly. Are you saying that code causes an instance of the remote service to be created? If so, that is incorrect. Nothing on the server is created until you execute the service. I believe using the send() method.

Or are you saying that this code causes an instance of the RemoteObject named sim to be created in your Flex application? If so, then that is probably true, although we can't tell for sure with just the code snippet you've provided.

You can create the RemoteObject conditionally in ActionScript. Or you could create the RemoteObject in a component other than the main component and initialize that component as you need to make remote calls.

www.Flextras.com
Though I may be wrong, what I meant to say is that upon loading the page, the constructor of the class behind SimulationWebService is being called. What I wanted to do was create an object using the destination from ActionScript instead of MXML.
duckworthd
To create one dynamically at runtime just do something like:var ro:RemoteObject = new RemoteObject();ro.destination = "SimulationWebService";ro.endpoint = "/foo/messagebroker/amf";ro.addEventListener("result", function(event:Event):void { // do something});More details on RemoteObject here:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/remoting/RemoteObject.html?allClasses=1
James Ward
Thanks James! Just what I was looking for.
duckworthd