help im new to robotlegs

jadd's Avatar

jadd

11 Jan, 2010 07:48 PM

hi all and first of all I'm sorry i'm very new to Robotlegs and for sure my post will be ridicolus. The question is how to load an xml before starting the real application. I was learning on how to working on the FlashGoogleMaps example. I would like to load an xml with some variables e.g.: apikey, zoom level, lat and long, before adding the map view. Anyone could help me? In attach the zip with the project (FB4 on Mac). Thanks in advance.

  1. Support Staff 1 Posted by Joel Hooks on 11 Jan, 2010 07:52 PM

    Joel Hooks's Avatar

    You will want to have a service, ApplicationXMLService.as as an example. In your app's Context startup method, you will dispatch an event to trigger a command. This command will access your service which will load the XML. Once this has been loaded and parsed you will dispatch an APP_XML_LOADED event that will likely trigger another command that will do any additional work you need to do to bootstrap your application. It might additionally trigger a listener on a mediator that will update your app's display.

  2. 2 Posted by jadd on 11 Jan, 2010 08:04 PM

    jadd's Avatar

    hi and thanks for the super fast reply Joel. Sorry but i'm very new to Robotlegs and if potentialy i could understand your answer, practicaly i can't. Any quick example available?

  3. Support Staff 3 Posted by Joel Hooks on 11 Jan, 2010 08:06 PM

    Joel Hooks's Avatar

    Almost all of the examples cover this general workflow. You've read the Best Practices document?

    http://wiki.github.com/robotlegs/robotlegs-framework/best-practices

  4. 4 Posted by jadd on 11 Jan, 2010 08:12 PM

    jadd's Avatar

    yes i did it and it seems very clear to me. I watched some video tutorial too. (pv3d e.g.) and evething seems easy but it's not. I will read the best practise again.

  5. 5 Posted by Andrei TT on 11 Jan, 2010 08:39 PM

    Andrei TT's Avatar

    I have a screencast on my blog that uses the workflow that Joel described. (I'm using RemoteObject to call functions on a PHP class but the idea is the same - instead of the RemoteObject you will use a URLLoader or an HTTPService and load the XML file).
    Unfortunately it doesn't have audio (i don't have a microphone) but it might help. take a look and let me know if you still don't understand the idea, i might find some time to provide you with an example and some more explanation.
    You can find the video at : http://andreitt.com/blog/?p=33

  6. 6 Posted by jadd on 11 Jan, 2010 09:19 PM

    jadd's Avatar

    hello andrei, i saw this morning your blog and now i've just finished to watch your video. It's a great resuorce for sure and i've appreciated it so much, but it's a little too advanced to me. Any other help with more explanation will be very much appreciated. Thanks a lot.

  7. 7 Posted by jadd on 11 Jan, 2010 09:22 PM

    jadd's Avatar

    Thanks andreii for your help. I will buy u a mic!!. Let me know how.

  8. 8 Posted by Andrei TT on 11 Jan, 2010 10:13 PM

    Andrei TT's Avatar

    that's some basic stuff i've shown in my video.
    anyway, you have to really understand this basics in robotlegs first before you can move on.
    Let me write up an elementary example and i'll explain every step of it. That should help you more. Just give me a day or so since i've just started working on a new commercial project and i've got a lot on my head these days.
    I'll post you the link here once i get it done.

    Also please start reading (if you haven't already) some papers on Dependency Injection to get a solid foundation on this concept. You should also be quite comfortable with object oriented programming and working with custom events in as3. If you don't have these basics it's nothing to worry, it's just that you need to get a grip into those before adventuring into robotlegs.
    Here's some material I found useful when I was learning myself:
    http://bit.ly/2Ia3KB - probably the easiest to understand intro to DI
    http://bit.ly/I0YAA - oldie but goodie
    http://bit.ly/2J7iZU - John's Hello World video which is very straightforward and easy to understand.
    And the Best Practices document which for me was the best resource.

  9. 9 Posted by Andrei TT on 12 Jan, 2010 12:32 AM

    Andrei TT's Avatar

    Ok. I got a few minutes free while I was installing some stuff i need and I made you a very quick and simple demo. I uploaded it as a flex project, so just import it in flex and and take a look at the classes.
    Here's the link: http://andreitt.com/robotlegs/basics/RLBasic.zip

    Note: look at the main class first since I described the whole workflow step by step there. That should be easy to understand. As you read that check out the classes (i pointed the classes you need to check at each point) for details. I also add comments at the most important steps to further underline what exactly happens there.

    Also notice that this is a very basic starter setup. You need to extend on it. I only load the xml, store it in the model and trace it out.

    PS: It's late at night and I'm quite tired so please excuse any spelling mistake. I hope this will clear this basics out for you. Let me know you thoughts after reading it all.

  10. 10 Posted by jadd on 12 Jan, 2010 05:14 AM

    jadd's Avatar

    Thanks Andrei for the informations. I did start with Robotlegs exactly via John's video and after reading the documentation. I had the impression of jump easy into it but I probably have to understand it a lot better and read the documentation again and again. And thanks a lot more for the example you post late last night, a great source for me your code. Thanks again. Roberto.

  11. 11 Posted by jadd on 12 Jan, 2010 08:38 AM

    jadd's Avatar

    Hi I'm here again and sorry. Thanks to Andrei I understand the workflow a lot better. But another thing I don't understand. Why (in the mainContext) if I write this code it works:

    commandMap.mapEvent(ContextEvent.STARTUP, LoadDataCommand, ContextEvent, true);
    commandMap.mapEvent(DataEvent.ON_DATA_LOADED, SetDataCommand , DataEvent, true);

    injector.mapSingleton(DataModel);
    injector.mapSingletonOf(IDataService, DataService);

    Instead of this (not working!) where ModelCommand contains the two injector instructions and ControlCommand contains the two command mapevent.

    commandMap.mapEvent(ContextEvent.STARTUP, ModelCommand, ContextEvent, true);
    commandMap.mapEvent(ContextEvent.STARTUP, ControlCommand, ContextEvent, true);

    Thanks.

  12. 12 Posted by jadd on 12 Jan, 2010 10:09 AM

    jadd's Avatar

    I'm very happy to say (finally!) I solved the problem. A wrong event and event handler In the ModelCommand. Thanks.

  13. 13 Posted by jadd on 13 Jan, 2010 07:03 PM

    jadd's Avatar

    ... even if working i'm not sure in what i did. Is this correct and/or best practice? I load my xml when the code above runs (the MapViewEvent.ON_MAP_VIEW_READY is dispatched and a MapViewMediator dispatch to the framework, then a command LoadDataCommand start everything).

    public class MapView extends Sprite
    {
        private var _map:Map;
    
        public function MapView()
        {
            addEventListener(Event.ADDED_TO_STAGE, onMapViewAddedToStage);
        }
    
        private function onMapViewAddedToStage(event:Event):void
        {
            dispatchEvent(new MapViewEvent(MapViewEvent.ON_MAP_VIEW_READY));
        }
    
  14. Support Staff 14 Posted by Shaun Smith on 13 Jan, 2010 07:20 PM

    Shaun Smith's Avatar

    That shouldn't be needed - if the view is mapped to a mediator you can be sure that it will be on the stage as soon as the mediator's onRegister() hook is called. In other words, you should simply be able to dispatch the ON_MAP_VIEW_READY event from the mediator's onRegister() hook.

  15. 15 Posted by jadd on 13 Jan, 2010 08:11 PM

    jadd's Avatar

    yes it's mapped to the mediator (or I presume it) above the code.

    public class ViewCommand extends Command
    {

    override public function execute():void
    {
    mediatorMap.mapView(MapView, MapViewMediator);
    }
    

    }

    Ant this is the Mediator:

    override public function onRegister():void
    {

    eventMap.mapListener(view, MapViewEvent.ON_MAP_VIEW_READY, onMapViewReady);
    eventMap.mapListener(eventDispatcher, MainEvent.ON_DATA_CHANGED, onDataChanged);
    

    }

    I'm missing something I guess.

  16. 16 Posted by jadd on 13 Jan, 2010 08:16 PM

    jadd's Avatar

    probably it's better to show you all my code (condensed).

    MapContext:

        override public function startup():void
        {
            commandMap.mapEvent(ContextEvent.STARTUP, ModelCommand, ContextEvent, true);
            commandMap.mapEvent(ContextEvent.STARTUP, ViewCommand, ContextEvent, true);
            commandMap.mapEvent(ContextEvent.STARTUP, ControlCommand, ContextEvent);
            commandMap.mapEvent(ContextEvent.STARTUP, StartupCommand, ContextEvent, true);
    
            dispatchEvent(new ContextEvent(ContextEvent.STARTUP));
        }
    

    ModelCommand:

        override public function execute():void
        {
            injector.mapSingleton(DataModel);
            injector.mapSingletonOf(IDataService, DataService);
        }
    

    ViewCommand:

        override public function execute():void
        {
            mediatorMap.mapView(MapView, MapViewMediator);
        }
    

    ControlCommand:

        override public function execute():void
        {
            commandMap.mapEvent(MapViewEvent.ON_MAP_VIEW_READY, LoadDataCommand, MapViewEvent);
            commandMap.mapEvent(DataEvent.ON_DATA_LOADED, SetDataCommand, DataEvent);
        }
    

    StartupCommand:

        override public function execute():void
        {
            contextView.addChild(new MapView());
        }
    

    MapView (now):

    public class MapView extends Sprite
    {
        private var _map:Map;
    
        public function MapView()
        {
            //addEventListener(Event.ADDED_TO_STAGE, onMapViewAddedToStage);
        }
    
        private function onMapViewAddedToStage(event:Event):void
        {
            //dispatchEvent(new MapViewEvent(MapViewEvent.ON_MAP_VIEW_READY));
        }
    
        public function initializeView(data:XML):void
        {
            trace("MapView :")      
        }
    

    MapMediator:

    public class MapViewMediator extends Mediator
    {
        [Inject]
        public var view:MapView;
    
        public function MapViewMediator()
        {
            super();
        }
    
        override public function onRegister():void
        {
            eventMap.mapListener(view, MapViewEvent.ON_MAP_VIEW_READY, onMapViewReady);
            eventMap.mapListener(eventDispatcher, MainEvent.ON_DATA_CHANGED, onDataChanged);
        }
    
        private function onMapViewReady(event:MapViewEvent):void
        {
            dispatch(new MapViewEvent(MapViewEvent.ON_MAP_VIEW_READY));
            eventMap.unmapListener(view, MapViewEvent.ON_MAP_VIEW_READY, onMapViewReady);
        }
    
        private function onDataChanged(event:MainEvent):void
        {
            //dispatch(new MainEvent(MainEvent.ON_MAP_DATA_REQUEST));
            trace("MapViewMediator : " + "onMapDataRequest" + event.data);
            view.initializeView(event.data);
    
            eventMap.unmapListener(eventDispatcher, MainEvent.ON_DATA_CHANGED, onDataChanged);
        }
    }
    
  17. 17 Posted by jadd on 14 Jan, 2010 08:01 AM

    jadd's Avatar

    working again, after reading documentation and mostly debuggin the application I ended up with this (I guess correct!):

        override public function onRegister():void
        {
            eventMap.mapListener(view, Event.ADDED_TO_STAGE, onMapViewReady);
            eventMap.mapListener(eventDispatcher, MainEvent.ON_DATA_CHANGED, onDataChanged);
        }
    
  18. 18 Posted by jadd on 14 Jan, 2010 10:55 AM

    jadd's Avatar

    I belive this post could be considered "resolved". Thanks to all.

  19. Till Schneidereit closed this discussion on 02 Mar, 2010 12:55 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