How to get a single instance in a mxml file

x8s9y's Avatar

x8s9y

24 Jun, 2015 02:24 AM

Use Flex module:
1.Create a module, add ContextBuilderTag in Declarations tag:

<fx:Declarations>
<mxml:ContextBuilderTag>
<mvcs:MVCSBundle/>
<config:ModelManagerConfig/>
</mxml:ContextBuilderTag>
</fx:Declarations>
2.config:ModelManagerConfig is my custom config: I create a ModelManagerModel single like this:
inject.map(ModelManagerModel).asSingleton();
3.I need to use the ModelManagerModel in a mxml file, but this mxml not mediator.
so how to get the ModelManagerModel ?

  1. Support Staff 1 Posted by Ondina D.F. on 24 Jun, 2015 07:10 AM

    Ondina D.F.'s Avatar

    Hi,

    The ViewProcessorMap is what you need:

    injector.map(SomeModel).asSingleton();
    viewProcessorMap.map(SomeView).toInjection();
    

    Then you inject SomeModel into SomeView:

    [Inject]
    public var someModel:SomeModel;
    

    Here the documentation:
    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...

    You can also search the forum for discussions about viewProcessorMap.

    Hope that helps.

    Ondina

  2. 2 Posted by x8s9y on 24 Jun, 2015 08:53 AM

    x8s9y's Avatar

    Thank you very much.
    I found https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/viewProcessorMap#shortcut-method-for-the-most-common-case-injection-by-inspection "The Robotlegs 2 view map is designed to allow views to be 'processed'...". Is that mean context don't install the ViewProcessormapExtension in RL.2?
    It works very good without install the ViewProcessormapExtension in RL.2 .

    2015-06-24

    x8s9y

    发件人:"Ondina D.F." <[email blocked]>
    发送时间:2015-06-24 15:10
    主题:Re: How to get a single instance in a mxml file [Robotlegs 2 #12983]
    收件人:"x8s9y"<[email blocked]>
    抄送:

  3. Support Staff 3 Posted by Ondina D.F. on 24 Jun, 2015 09:16 AM

    Ondina D.F.'s Avatar

    You're welcome!

    Is that mean context don't install the ViewProcessormapExtension in RL.2?

    When you create a Context, you tell it to install the MVCSBundle, as you did.
    If you're using the default MVCSBundle, the ViewProcessormapExtension will be installed automatically. Take a look at the MVCSBundle and see all the extensions installed by default:
    https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...

    It works very good without install the ViewProcessormapExtension in RL.2 .

    No, it doesn't. You can verify that by creating a custom MVCSBundle where you comment out the ViewProcessorMapExtension.

  4. 4 Posted by x8s9y on 24 Jun, 2015 10:40 AM

    x8s9y's Avatar

    yes,I use the MVCSBundle.
    Thank you very much.

    2015-06-24

    x8s9y

    发件人:"Ondina D.F." <[email blocked]>
    发送时间:2015-06-24 17:16
    主题:Re: How to get a single instance in a mxml file [Robotlegs 2 #12983]
    收件人:"x8s9y"<[email blocked]>
    抄送:

  5. Support Staff 5 Posted by Ondina D.F. on 24 Jun, 2015 01:34 PM

    Ondina D.F.'s Avatar

    No problem.

  6. Ondina D.F. closed this discussion on 24 Jun, 2015 01:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac