Robotlegs with FlexNativeEvent

face1's Avatar

face1

21 Sep, 2011 03:52 PM

I am using the Robotlegs framework and I am busy with an AIR desktop application and I want to use FlexNativeMenu. The problem is that I am not able to create a view class based on mx.controls.FlexNativeMenu for dependency injection and hence not a mediator. I am using HTTPService (in my non-Robotlegs application) to read the menu XML file and then using the code below to update the menu - pretty straighforward. Also, what is also a bit strange about this is that the class is FlexNativeMenu, but the spark container is <s:menu> - which is not a class. Any help will be greatly appreciated. Thanks.

<s:menu>
<mx:FlexNativeMenu id="mainMenu" dataProvider="{menuService.menu}" labelField="@label" keyEquivalentField="@keyEquivalent" showRoot="false"/> </s:menu>

  1. Support Staff 1 Posted by Ondina D.F. on 21 Sep, 2011 05:24 PM

    Ondina D.F.'s Avatar

    Hi face1,

    This works:

    In your Context: mediatorMap.mapView(SomeNativeMenuView, SomeNativeMenuMediator);

    SomeNativeMenuView is <s:Group
    having a <s:Button id="openMenu"

    The script:

    
                import mx.collections.ArrayCollection;
                import mx.controls.FlexNativeMenu;
    
                private var someNativeMenu:FlexNativeMenu;
    
                public function setMenuDataProvider(dataProvider:ArrayCollection):void
                {
                    someNativeMenu=new FlexNativeMenu();
                    someNativeMenu.dataProvider=dataProvider;
                    someNativeMenu.labelField="label";
                    someNativeMenu.showRoot=false;
                    someNativeMenu.setContextMenu(openMenu);
                }
    

    SomeNativeMenuMediator

    
    import org.robotlegs.mvcs.Mediator;
    
        public class SomeNativeMenuMediator extends Mediator
        {
            public function SomeNativeMenuMediator()
            {
            }
            [Inject]
            public var view:SomeNativeMenuView;
            
            override public function onRegister():void
            {
                eventMap.mapListener(eventDispatcher, SomeServiceEvent.DATA_RECEIVED, onDataReceived);
            }
            
            protected function onDataReceived(event:SomeServiceEvent):void
            {
                view.setMenuDataProvider(event.someData);
            }
        }
    

    Try it and tell if it helps:)

    Ondina

  2. Support Staff 2 Posted by Ondina D.F. on 22 Sep, 2011 06:02 PM

    Ondina D.F.'s Avatar

    You can not create a custom MXML component based on FlexNativeMenu, if that’s what’s confusing you. It isn’t a Robotlegs issue, but rather a Flex/AIR one:)
    If you don’t want to create a component as in my previous example, then
    you can use the WindowedApplication (your ContextView) to hold the

    <s:menu>

     <mx:FlexNativeMenu id="someNativeMenu"/>
    

    </s:menu>

    and create a mediator for the ContextView, which will then set the dataProvider as in my example from the previous post.

    The method in the ContextView would be like this.

    
    public function setMenuDataProvider(dataProvider:ArrayCollection):void
    {
       someNativeMenu.dataProvider=dataProvider;
       someNativeMenu.labelField="name";
       someNativeMenu.showRoot=false;
       someNativeMenu.setContextMenu(this);
    }
    

    HTH

  3. 3 Posted by face1 on 26 Sep, 2011 11:15 AM

    face1's Avatar

    Ondina - thank you for your help - I will try your suggestions and get back soon.

  4. Support Staff 4 Posted by Ondina D.F. on 16 Nov, 2011 09:23 AM

    Ondina D.F.'s Avatar

    Hi face1,
    Feel free to reopen this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues.
    Thank you for posting.
    Ondina

  5. Ondina D.F. closed this discussion on 16 Nov, 2011 09:23 AM.

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