Well, our package cache seems to have worked.
Here is a rundown of the small changes we've made to the loaderMax code.
Added loading/IFileCache.as:
package com.greensock.loading
{
import flash.net.URLRequest;
import flash.utils.ByteArray;
/**
* ...
* @author Liam Routt
*/
public interface IFileCache
{
function findAsset ( url:URLRequest ) : ByteArray;
}
}
Change to loading/LoaderMax.as:
@@ -152,6 +152,8 @@
public static var defaultContext:LoaderContext;
/** The class used by ImageLoaders, SWFLoaders, and VideoLoaders to create the containers into which they'll dump their rawContent - by default it is the com.greensock.loading.display.ContentDisplay class but if you're using Flex, it is typically best to change this to com.greensock.loading.display.FlexContentDisplay. You only need to do this once, like
import com.greensock.loading.LoaderMax;
import com.greensock.loading.display.FlexContentDisplay;
LoaderMax.contentDisplayClass = FlexContentDisplay; **/
public static var contentDisplayClass:Class;
+
+ public static var fileCache:IFileCache;
/** @private **/
protected var _loaders:Array;
Changes to loading/core/DisplayObjectLoader.as:
// in the headers
+ import flash.utils.ByteArray;
@@ -93,15 +94,25 @@
}
}
if (Capabilities.playerType != "Desktop") { //AIR apps will choke on Security.allowDomain()
Security.allowDomain(_url);
}
- _loader.load(_request, _context);
+
+ var bytes:ByteArray;
+
+ if ( LoaderMax.fileCache ) {
+ bytes = LoaderMax.fileCache.findAsset(_request);
+ }
+ if ( bytes ) {
+ _context = null;
+ _loader.loadBytes(bytes, _context);
+ } else {
+ _loader.load(_request, _context);
+ }
}
/** @inheritDoc **/
override public function auditSize():void {
if (Capabilities.playerType != "Desktop") { //AIR apps will choke on Security.allowDomain()
Security.allowDomain(_url);
}
super.auditSize();
}
Basically, this adds a public var to LoaderMax which allows the provision of a file cache with the one interface function which returns either null or the ByteArray for the display object as found in the cache.
Our only real stumbling block here was having to provide a null context for the loadBytes call, otherwise what we loaded wasn't able to be used as it would have been after a normal load.
It is left to the integrator to provide such a file cache, and to populate it. We managed to easily put together a dictionary-based zip file processor which was able to accept the url and determine whether the relevant file was in one of the zips it had processed. We have both persistent and temporary zips in our cache, so that we can flush some data and keep the stuff we know we will want to use again.
I hope this approach is of use to someone else.
Liam Routt
Media Saints