tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/8000-loading-graphics-xml-and-other-resources-that-should-be-used-in-the-application-everywhereRobotlegs: Discussion 2013-12-23T09:24:30Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-12T10:44:58Z2013-11-12T10:44:58ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>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.</p>
<p>here is graphics embedding operation:<br>
<a href=
"https://github.com/Stray/robotlegs-demo-StrategyGame/blob/master/assets/skins/PyramidGameSkin.as">
https://github.com/Stray/robotlegs-demo-StrategyGame/blob/master/as...</a></p>
<p>here is the usage:<br>
<a href=
"https://github.com/Stray/robotlegs-demo-StrategyGame/blob/master/src/strategy/view/SkyView.as">
https://github.com/Stray/robotlegs-demo-StrategyGame/blob/master/sr...</a></p></div>naghekyantag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-12T11:22:35Z2013-11-12T11:22:35ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>I'm very sorry, but I'm running out of time today.<br>
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.</p>
<p>See if this is at least a source of inspiration:<br>
<a href=
"https://github.com/Matan/AssetLoader">https://github.com/Matan/AssetLoader</a><br>
<a href=
"http://doesflash.com/assetloader/">http://doesflash.com/assetloader/</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-12T12:16:03Z2013-11-12T12:16:03ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>You can try LoaderMax from greensock. Just make a service
ILoader and implement it in MVCS diagram.</p>
<p>you would map it like this</p>
<p>var loader:ILoader =
injector.intantiateUnmapped(LoaderService);<br>
injector.map(ILoader).toValue(loader);</p>
<p>this way your LoaderService will be injected with dependencies
if needed.</p>
<p>If you are finished with your loader, you can unmap it and
destroy it.</p>
<p>hope it helps</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-12T12:19:35Z2013-11-12T12:19:35ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>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.</p>
<p>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.<br>
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.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-13T17:51:09Z2013-11-13T17:54:51ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>@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? :)</p>
<p>@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!</p></div>naghekyantag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-13T18:33:26Z2013-11-13T18:33:26ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>It uses the injector to instantiate the class. that way all your
classes are created in injector(factory) which makes it great for
testing.</p>
<p>It is like making injector calling new Class(), but then it
populates inject tags and constructor params if they are mapped
before in injector.</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T06:35:57Z2013-11-14T06:37:26ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>@Matej I get compile error when I call that function. In which
version of RL it is present?</p>
<p>And, finally, why just I can't map it as a singleton?</p></div>naghekyantag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T07:01:43Z2013-11-14T07:01:43ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>What error do you get?</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T09:01:08Z2013-11-14T09:01:08ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>You might as well map it as a singleton, no?</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T10:02:56Z2013-11-14T10:02:56ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>This way you map the value agains interface only, and injecting
the class itself will not work.<br>
But you still instantiate the class with injector, for dependency
and testability.</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T10:12:26Z2013-11-14T10:12:26ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>To achieve the same with the added benefit of lazy instantiation
you can do:</p>
<p>injector.map(ILoader).toSingleton(LoaderService)</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T10:14:44Z2013-11-14T10:14:44ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>Ah thx, I didn’t know you could pass the params to
toSingleton();</p>
<p>usually I used that for injector.map(Class).toSingleton();</p>
<p>:)</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/299108332013-11-14T12:13:56Z2013-11-14T12:13:56ZLoading graphics, xml and other resources that should be used in the application everywhere<div><p>Careful though, it's</p>
<p>injector.map(IFooService).**to**Singleton(FooService)</p>
<p>and</p>
<p>injector.map(FooService).**as**Singleton()</p></div>creynders