简体   繁体   English

使用Parsley Flex移动

[英]Flex mobile using Parsley

I'm using Parsley in my flex mobile project. 我在我的flex移动项目中使用Parsley。 I have multiple destination services but I can't find more resources on how to add another destination service to config.xml file. 我有多个目标服务,但我找不到更多有关如何将另一个目标服务添加到config.xml文件的资源。 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: 更新: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. 通过ID注入并不是一种好的做法,因为您创建了一个基于名称的依赖项。 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. 我将添加一个简单的示例,向您展示如何将该技术与多个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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM