New issue 90 by frederic...@gmail.com: Customize AssetLocator for getting
content through it
http://code.google.com/p/sekati/issues/detail?id=90
Purpose of the enhancement request:
I suggest to use a new dictionary in asset locator for registered content
So the getContent method can acces directly to the content
Would this request break the existing API, add new functionality or both?
no at all
Please use labels, example code and attachments to provide additional info:
package sekati.load {
import ideal.singleton.logger;
import flash.utils.Dictionary;
/**
* AssetLocator provides a weak-referenced <code>Dictionary</code> of
<i>all</i> <code>ILoader</code> instances.
*/
public class AssetLocator {
/*** @private */
private static var loaderStack : Dictionary = new Dictionary( true );
private static var contentStack : Dictionary = new Dictionary( true );
/**
* Register an asset for weak referencing by
<code>AbstractLoader.url</code> property.
* @param l the <code>AbstractLoader</code> instance to register.
*/
public static function register(name : String, l : AbstractLoader, c:*) :
void
{
trace("AssetLocator register : " + name);
loaderStack[name] = l;
contentStack[ name ] = c;
}
/**
* Unregister an asset for by <code>AbstractLoader.url</code> property.
* @param url the <code>AbstractLoader.url</code> identifier property.
*/
public static function unregister(name : String) : void {
loaderStack[name] = null;
contentStack[ name ] = null;
}
/**
* Determine whether an <code>AbstractLoader</code> has been registered
or not.
*/
public static function isRegistered(name : String) : Boolean {
return (loaderStack[name] != null);
}
/**
* Return the weak referenced <code>AbstractLoader</code> instance.
* @param url the <code>AbstractLoader.url</code> identifier property.
*/
public static function getLoader(name : String) : AbstractLoader
{
if (isRegistered( name ))
{
//trace( stack[name] );
return loaderStack[name] as AbstractLoader;
} else {
logger.error( AssetLocator, name + " is not registered." );
return null;
}
}
public static function getContent(name : String ) : *
{
if ( isRegistered( name ))
{
//trace("AssetLocator", stack[name] );
return contentStack[ name ];
}
else
{
logger.error( AssetLocator, name + "is not registered." );
return null;
}
}
}
}
ok but in order to run properly, we don't register asset in assetLocator
from AbstractLoader but from each type of loader
so we need to override initHandler
and add a new method "registerAsset" in every loader class
override protected function initHandler(e : Event) : void
{
super.initHandler( e );
registerAsset();
}
override protected function registerAsset():void
{
AssetLocator.register(_name, this, content );
}
what to you think about ?
cheers
fred
Comment #1 on issue 90 by sekati: Customize AssetLocator for getting
content through it
http://code.google.com/p/sekati/issues/detail?id=90
Thanks for your submission - I'll review/test & merge into the next
release if all goes well!
Jason / Sekati
Comment #2 on issue 90 by sekati: Customize AssetLocator for getting
content through it
http://code.google.com/p/sekati/issues/detail?id=90
I believe this could be similarly managed with sekati.core.KeyFactory if
one desires.