Loading graphics, xml and other resources that should be used in the application everywhere

naghekyan's Avatar


11 Nov, 2013 08:48 AM

Let's say I am programming a game using Robotlegs 2. Consider I have a .fla file that exports .swf that contains all popups, buttons and other graphics. Also I have XML files that are responsible for localization and other settings. All the listed resources I should load somewhere and use them very frequently. The Robotlegs architecture tells us to load them via services, save them in models and access the data by dispatching events from views. But as I am going to need them very frequently and in each and every view. Maybe I need to inject this data in view? Or it would be against the philosophy of Robotlegs?

  1. 1 Posted by naghekyan on 12 Nov, 2013 10:44 AM

    naghekyan's Avatar

    This is really an important and common problem. Please help me. I have seen implementations with skins but those are not loaded dynamically. I want to load the resources dynamically. An I don't know how to organize the flow - RL standard flow or I can deviate in some way and it would be still good from the point of design.

    here is graphics embedding operation:

    here is the usage:

  2. Support Staff 2 Posted by Ondina D.F. on 12 Nov, 2013 11:22 AM

    Ondina D.F.'s Avatar

    I'm very sorry, but I'm running out of time today.
    You'll really have to go through discussions on this forum to see what's more appropriate for you or wait for someone else to chip in to give you advice.

    See if this is at least a source of inspiration:

  3. 3 Posted by matej on 12 Nov, 2013 12:16 PM

    matej's Avatar

    You can try LoaderMax from greensock. Just make a service ILoader and implement it in MVCS diagram.

    you would map it like this

    var loader:ILoader = injector.intantiateUnmapped(LoaderService);

    this way your LoaderService will be injected with dependencies if needed.

    If you are finished with your loader, you can unmap it and destroy it.

    hope it helps

  4. Support Staff 4 Posted by creynders on 12 Nov, 2013 12:19 PM

    creynders's Avatar

    I tend to load graphics as separate modules into the appropriate application domains, from then on any views can instantiate the graphic classes directly, no need for injections or anything.

    I regard localization as part of the view tier, potentially infused/populated through a service. Depending on what I use for localization (resource bundles or a 3rd party lib) my approach differs, but in a pure AS3 project I have either an embedded XML file (i.e. compiled into the .swf) or I have an external XML file which is loaded by a service and fed to the localization framework. I access the localization framework from the views directly, either by having the mediator pass the localization facade instance to the view, or by using a direct access mechanism provided by the localization framework itself (e.g. a static or singleton instance). It's not the cleanest solution, but it is the most pragmatic one.
    Localization is hard and cumbersome, that's why you won't find a lot of clear-cut examples or tutorials. I've never found a REALLY neat way to deal with it.

  5. 5 Posted by naghekyan on 13 Nov, 2013 05:51 PM

    naghekyan's Avatar

    @Matej, it could help if Google could find intantiateUnmapped function in any other page other then this in all over the internet. What is this? :)

    @creynders thanks, your description (load graphics as separate modules into the appropriate application domains) is one of the ways I thought to go. And really this is hard and cumbersome, but embedded XML file sounds really good!

  6. 6 Posted by matej on 13 Nov, 2013 06:33 PM

    matej's Avatar

    It uses the injector to instantiate the class. that way all your classes are created in injector(factory) which makes it great for testing.

    It is like making injector calling new Class(), but then it populates inject tags and constructor params if they are mapped before in injector.

  7. 7 Posted by naghekyan on 14 Nov, 2013 06:35 AM

    naghekyan's Avatar

    @Matej I get compile error when I call that function. In which version of RL it is present?

    And, finally, why just I can't map it as a singleton?

  8. 8 Posted by matej on 14 Nov, 2013 07:01 AM

    matej's Avatar

    What error do you get?

  9. Support Staff 9 Posted by creynders on 14 Nov, 2013 09:01 AM

    creynders's Avatar

    You might as well map it as a singleton, no?

  10. 10 Posted by matej on 14 Nov, 2013 10:02 AM

    matej's Avatar

    This way you map the value agains interface only, and injecting the class itself will not work.
    But you still instantiate the class with injector, for dependency and testability.

  11. Support Staff 11 Posted by creynders on 14 Nov, 2013 10:12 AM

    creynders's Avatar

    To achieve the same with the added benefit of lazy instantiation you can do:


  12. 12 Posted by matej on 14 Nov, 2013 10:14 AM

    matej's Avatar

    Ah thx, I didn’t know you could pass the params to toSingleton();

    usually I used that for injector.map(Class).toSingleton();


  13. Support Staff 13 Posted by creynders on 14 Nov, 2013 12:13 PM

    creynders's Avatar

    Careful though, it's




  14. Ondina D.F. closed this discussion on 23 Dec, 2013 09:24 AM.

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

Keyboard shortcuts


? 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