Flex mobile using Parsley

I'm using Parsley in my flex mobile project. I have multiple destination services but I can't find more resources on how to add another destination service to config.xml file. The file is as below:

<objects 
    xmlns="http://www.spicefactory.org/parsley"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.spicefactory.org/parsley 
        http://www.spicefactory.org/parsley/schema/2.4/parsley-core.xsd">


    <object type="mx.rpc.remoting.RemoteObject" id="genBUS">
        <property name="destination" value="genBUS"/>
        <property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
    </object>
</object>

In the case when I create another

<object type="mx.rpc.remoting.RemoteObject" id="anotherBUS"></objects>

and do

[Inject(id='genBUS')]
public var genBUS:RemoteObject;

it complains that I have defined multiple remote objects. How does it work? How can I inject another destination service? That would be great to gain more knowledge about Parsley...

UPDATE: config.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Object 
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns="http://www.spicefactory.org/parsley">


    <Object id="genBUS" type="mx.rpc.remoting.RemoteObject">
        <Property name="destination" value="genBUS" />
        <Property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
    </Object>

    <Object id="karBUS" type="mx.rpc.remoting.RemoteObject">
        <Property name="destination" value="karBUS" />
        <Property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
    </Object>


</mx:Object> 

Injecting by ID is not considerer to be good practice because you create a name-based dependency. Change the name, or make a typo, and your application breaks and it's hard to debug that.

So as a general rule you should try to avoid it. The Parsley docs explain how to do this. I'll just add a simple example to show you how you'd use that technique with your multiple RemoteObjects.

<fx:Object xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:p="http://www.spicefactory.org/parsley">

<fx:Script>
    import path.to.service.GenBusDelegate;
    import path.to.service.KarBusDelegate;
</fx:Script>

<fx:Declarations>
    <fx:String id="gateway">http://localhost:8080/ClinASM/messagebroker/amf</fx:String>

    <s:RemoteObject id="genBus" destination="genBus" endpoint="{gateway}" />
    <s:RemoteObject id="karBus" destination="karBus" endpoint="{gateway}" />

    <p:Object type="{GenBusDelegate}">
        <p:ConstructorArgs>
            <p:ObjectRef idRef="genBus" />
        </p:ConstructorArgs>
    </p:Object>

    <p:Object type="{KarBusDelegate}">
        <p:ConstructorArgs>
            <p:ObjectRef idRef="karBus" />
        </p:ConstructorArgs>
    </p:Object>

</fx:Declarations>
</fx:Object>

or if you don't want to use constructor arguments:

    <p:Object type="{GenBusDelegate}">
        <Property name="remoteObject" idRef="genBus"/>
    </p:Object>
链接地址: http://www.djcxy.com/p/34658.html

上一篇: Flex移动项目问题

下一篇: Flex移动使用欧芹