开发者

How can I inject a dictionary using parsley framework in as3?

In my parsley container, I'm instantiating an object 'A' that contains a Dictionary (flash.utils.Dictionary).

I would like to create this Dictionary using parsley and inject it to 'A'. This dictionary pairs structure is: key=id of object 'B', value='B' where object 'B' is also an object which is defined and created using parsley (so basically the pairs structure is and object id as a key and the object itself as the value).

Now, I have no problem creatin开发者_运维知识库g 'A' and 'B', but can't seem to find the right way to create this dictionary using parsley, nor injecting it to 'A'.

Any help is highly appreciated!

Thanks in advance, Yogev


You can do this in the context.mxml:

<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml" 
           xmlns="http://www.spicefactory.org/parsley">

    <mx:Script>
            <![CDATA[
                import com.example.ObjectToInjectX; 
                import com.example.ObjectToInjectY;
                import com.example.MyExampleObject;

            ]]>
    </mx:Script>

    <!-- The class to inject the map into, just declare -->
    <Object type="{MyExampleObject}" id="myExampleObject" />

    <!-- Objects to inject into the Dictionary -->
    <Object type="{ObjectToInjectX}" id="objectToInjectX" />
    <Object type="{ObjectToInjectY}" id="objectToInjectY" />

    <!-- The Dictionary -->
    <Object type="{Dictionary} id="myDictionaryToInject" />
        <DynamicProperty name="itemX" idRef="objectToInjectX" />
        <DynamicProperty name="itemY" idRef="objectToInjectY" />
    </Object>

</mx:Object> 

Then simply in the class you want to inject to do the following:

public class MyExampleObject
{
     private var _myDictionaryToInject:Dictionary;

     [Inject(id="myDictionaryToInject")]
     public function set myDictionaryToInject( myDictionaryToInject:Dictionary ):void
     {
            _myDictionaryToInject = myDictionaryToInject;
     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜