0

私はフレックスモバイルプロジェクトでパセリを使用しています。複数の宛先サービスがありますが、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> 
4

1 に答える 1

2

名前ベースの依存関係を作成するため、IDによる注入は適切な方法とは見なされません。名前を変更するか、タイプミスをすると、アプリケーションが壊れてデバッグが困難になります。

したがって、原則として、それを避けるようにしてください。パセリのドキュメントでは、これを行う方法について説明しています。簡単な例を追加して、複数のRemoteObjectでその手法をどのように使用するかを示します。

<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>
于 2012-03-29T12:15:39.820 に答える