Alternativa 8.27.0 Undocumented ResourceLoader

David Jones

It was pointed out to me recently by the alternativa3d guys that there is actually another loader in their engine other than the TextureLoader called ResourceLoader. Its not documented but it provides a progress event which isn’t available in the TextureLoader and I desperately needed this for a project of mine. Seen as its currently undocumented I thought I’d spend a brief moment explaining how to use it. I’m taking the parsersexample that comes with the alternativa files to illustrate how to use this new class. You should be able to find it at Alternativa3d_8.27.0\Alternativa3DExamples\src\parsersexample. Once we have access to the file we need to add 2 new includes to it, so add these somewhere at the top.

import alternativa.engine3d.loaders.ResourceLoader;

Then add these variables that we are going to use to get the percentage loaded.

private var itemsTotal:Number = 0;
private var itemsLoaded:Number = 0;

Once thats done we need to switch out the TextureLoader and use our new ResourceLoader. So find the following lines and comment them out or remove them.

//var texturesLoader:TexturesLoader = new TexturesLoader(stage3D.context3D);

Then just below this add the following

itemsTotal = textures.length;
var resldr:ResourceLoader = new ResourceLoader();
resldr.addEventListener(ProgressEvent.PROGRESS, onProgress);
resldr.addEventListener(Event.COMPLETE, onComplete);

This will setup a new instance of the resourceloader and listen for a couple of events. We then pass in the vector of our textures this is the same one that was used in texturesloader, then we just run load to get things moving. Before we run this code we need the 2 functions for the events too so add these somewhere in the parsersexample.

private function onProgress(e:ProgressEvent):void
    	var percentLoaded:Number = itemsLoaded / itemsTotal;
    	percentLoaded = Math.round(percentLoaded * 100);
    	trace(percentLoaded + "%");
private function onComplete():void

Normally I would do something like this code below to get the percentage but the bytesloaded and bytestotal always returned 0 so I scrapped that used the above solution.

var percentLoaded:Number = e.bytesLoaded / e.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace(percentLoaded + "%");

I’ve put this code into a seperate “Examples” folder that you can use with the other alternativa3d examples to try this out. Download the files here



  • avatar-jan
    # Jan

    Hello davidejones,

    thank you very much for the explanation of the ResourceLoader. I tried to implement it to my project but I failed. On compiling it says that Definition alternativa.engine3d.loaders:ResourceLoader could not be found.

    Eventhough its marked blue when i write it and it also has a declaration.

    greetings Jan

  • avatar-davidejones
    # davidejones
    you may need to check the latest source code and see if it still exists and if there are any changes!

Comments are currently closed