pureMVC assetLoader utility (4)

Changes
I have done some more twiddling. Mainly I realised that I needed a finer grained status than isLoaded, so I removed it and substituted a status property, whose values are enumerated in org.puremvc.as3.utilities.assetLoader.etypes.AssetInfoStatus:

  • LOADED_COMPLETE: the asset has loaded and is ready for retrieval
  • QUEUED: the asset is queued, but yet to start loading
  • LOADING: the asset is currently loading
  • ERROR: the asset failed to load, details will have been sent via the LoaderErrorEvent
  • READY: the asset has been called through the getAsset() method, has not previously been loaded and is ready to be added to the queue
  • NON_EXISTENT: the asset does not yet exist
  • I have also fixed a hole in the getAsset method logic, where it was only looking in the assetMap, not the loadQueue, or the currently loading item.
    [kml_flashembed movie=”http://www.revisual.co.uk/swf/assetloader_v3.swf” height=”500″ width=”470″ /]
    To retrieve an asset:

    // create assetInfo
    var assetInfo:IAssetInfo;
    assetInfo= assetLoader.getAsset("filePath/myImage.jpg");
    // test to see if it has already been loaded and stored
    if(assetInfo.status != AssetInfoStatus.READY)
    {
        trace("this asset has already been loaded");
        // retrieve and type asset;
        var myBMP:Bitmap = Bitmap( assetInfo.getAsset() );
    }
    else
    {
        // add the id of the client that should 
        // handle the loading of the asset
        assetInfo.clientType = ClientTypes.LOADER_CLIENT;
        // add a LoaderContext or SoundLoaderContext if needed
        assetInfo.context = new LoaderContext();
        // add any listeners required
        assetInfo.addEventListener(Event.COMPLETE, 
                                   completeHandler);
        // add the assetInfo to the load que
        assetLoader.addToQue(assetInfo);
    }

    4 thoughts on “pureMVC assetLoader utility (4)

    1. I’m not quite sure how that works, but im sure its very clever! Would be interesting to hear a bit about it.

    2. OK , im nearly as confused now you explained it. One things for sure your very clever!

      Can it load AS2 and AS3 assets?

    3. well, its written is as3, so obviously as3 is in. As3 can load as2 assets, but can only play them, not interact with them.

      of course if yould like to port it to as2, i’ll stick it up (on the site of course).

      One things for sure, you sure is sarcastic :~/

    Leave a Reply

    Your email address will not be published. Required fields are marked *