sharing loader in more assetloaders
Home › Forums › AssetLoader › I Need Help! › sharing loader in more assetloaders
Tagged: AssetLoader, StatsMonitor
This topic has 2 voices, contains 12 replies, and was last updated by Matan Uberstein 116 days ago.
| Author | Posts |
|---|---|
| Author | Posts |
| January 22, 2012 at 8:56 pm #751 Quote | |
|
|
<p>Hi,</p>
<p>I am using AssetLoader for some time and it is really awesome library. I really appreciate your work on it. Thanks!</p> <p>But i got into problem and i dont know if it is possible to solve it with AL. These are my scenarios:</p> <p>1. after specific mouse event i am requesting files A, B, C, D, E which contains one specific part of animation. this can be easily made by AssetLoader container and adding Loaders for every file. when AssetLoader dispatches oncomplete signal i can use all downloaded graphics as a whole.</p> <p>2. before oncomplete signal dispatches there will be new mouse event requesting for graphics B, C, F, G. in this scenario i want to share existing loaders from first requests for files B and C in the new AssetLoader container with other loaders for files F and G. so when loaders A and B ends downloading it will dispatch in both AssetLoaders. </p> <p>problem is that i am getting error that loader is already contained by other loader which is logical. it is possible to somehow bypass this in AL ? </p> |
| January 22, 2012 at 9:06 pm #877 | |
|
Matan Uberstein |
Hi there, Thanks for using AssetLoader and those very kind words Hope that helps! Let me know if I can be of further assistance! |
| January 23, 2012 at 10:35 am #878 | |
|
|
Hi, thanks for advice, but there is new problem. i can add started ILoaders to new monitor, but they will not dispatch. when i move loader.start() outside of conditional scope i will download duplicated files. i dont know if it is good, so please check the code below. 1 |
| January 23, 2012 at 10:57 am #879 | |
|
Matan Uberstein |
Ooooh, I’m a bit confused with what you’re trying to achieve, but it feels like your code needs a bit of restructure. There is no need to re-download anything, you have access to all your assets via the parent (root IAssetLoader) – if you so choose. I’d suggest breaking your code apart into sections. Have focus small pieces of logic that only does 1 thing at a time. E.g. The piece of code you gave above doesn’t make sense, because the naming doesn’t match with what it’s trying to do. You are calling “loadAssets” but it conditionally loads something and it returns a StatsMonitor. Why not create the loading Queue (Root IAssetLoader) and a StatsMonitor up front. Add the assets into the StatsMonitor as you see fit, then invoke start on the root IAssetLoader or sub groups of the IAssetLoader. — Whatever needs to be loaded. Are you using a design pattern to build your application? Something like MVC? If not, I’d suggest you do. I hope this helps in some way, sorry I can’t be of more help, I really don’t have much to go on. |
| January 23, 2012 at 12:41 pm #880 | |
|
|
sorry… i explain what i want to do. make it clear, I will rename loadAssets function to loadMonitorForAssets(assets:Array). this function should return monitor (or IAssetLoader – this was the first bad solution) or something what will be used for listening on download completion for all the loaders(files). it is used throughout my code several times. example of using function in Client class: when monitor dispatches onComplete signal i can start drawing. but problem is when i want register one loader to 2 monitors. example of two monitors with shared loader: so steps in loadMonitoForAssets function in AssetManager looks like this: 2. checking every item in assetsArray if the loader already exists for this asset in the root IAssetLoader. 3A. if exists then get existing loader 3B. if does not exist then create new loader, add him to root IAssetLoader and initiliaze him 4. add loader to monitor when i add new loaders to monitor it will dispatch onComplete event, but with existing loaders it doesnt. i hope that it is now clear. |
| January 23, 2012 at 12:50 pm #881 | |
|
Matan Uberstein |
Ah yes, much better. Well the solution is really simple: Once your monitor is created and all the loaders are added into the monitor, check whether all the children are loaded: If the loaders are loaded and you want to continue using the onComplete handler in your code, fake the dispatch manually: Your application should continue without knowing the difference. |
| January 23, 2012 at 1:06 pm #882 | |
|
|
your solution works only for already loaded content. but registering loaders which are in progress they will not dispatch onComplete event. example which is not working: but when i start loader after adding it to monitor it is working: so, in my situation i can bypass it by restarting loader: simply… when i add existing loader which is in progress to the new monitor it is not dispatching onComplete signal. |
| January 23, 2012 at 1:15 pm #883 | |
|
|
i forgot to say, that loaded content is checked with 1 |
| January 23, 2012 at 1:20 pm #884 | |
|
Matan Uberstein |
Hmm, ok, the only thing I can think of is that the StatsMonitor needs at least 1 child asset to fire off onStart to make the onComplete eventually fire. https://github.com/Matan/AssetLoader/blob/master/src/org/assetloader/base/StatsMonitor.as#L71 So, if an assets is added to the monitor which hasn’t been loaded yet, make sure you call .start after adding it the monitor. |
| January 23, 2012 at 1:28 pm #885 | |
|
|
and there is problem with duplicating files… this will duplicate loader and start downloading same file (in progress) again: this is my restart bypass: |
| January 23, 2012 at 1:43 pm #886 | |
|
Matan Uberstein |
I get your point, the StatsMonitor will be re-written in v3, in the meantime, why not extend the class and add your own functionality? All you need to add is a simple function that validates the current state of the added children, then dispatch onComplete. |
| January 23, 2012 at 1:55 pm #887 | |
|
|
yeah, actually i am writing AssetLoaderContainer class which register ILoaders and dispatch special event when they will be completed. so, thanks for the clarification. :] |
| January 23, 2012 at 1:58 pm #888 | |
|
Matan Uberstein |
|
You must be logged in to reply to this topic.







