使用Parsley Flex移动

时间:2012-03-29 10:46:04

标签: flex flex4 flex4.5 flex-mobile parsley

我在我的flex移动项目中使用Parsley。我有多个目标服务,但我找不到更多有关如何将另一个目标服务添加到config.xml文件的资源。该文件如下:

<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>

在我创建另一个

的情况下
<object type="mx.rpc.remoting.RemoteObject" id="anotherBUS"></objects>

并做

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

它抱怨我已经定义了多个远程对象。它是如何工作的?如何注入其他目标服务?获得更多关于欧芹的知识会很棒...

更新: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> 

1 个答案:

答案 0 :(得分:2)

通过ID注入并不是一种好的做法,因为您创建了一个基于名称的依赖项。更改名称,或输入错误,您的应用程序中断,很难调试。

因此,作为一般规则,您应该尽量避免它。欧芹文档explain how to do this。我将添加一个简单的示例,向您展示如何将该技术与多个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>

或者如果您不想使用构造函数参数:

    <p:Object type="{GenBusDelegate}">
        <Property name="remoteObject" idRef="genBus"/>
    </p:Object>