| LowRA API Documentation | Annexes | All Packages | All Classes | Index | Frames |
|
| How to <rsc> node to load resources | ||
You will find below the various methods to define resources to load during application assembling of LowRA IoC.
Resources are files that are loaded at the same time as application display object and dynamic libraries ( <dll> ).
To define a resource to load, just use the <rsc> node in your xml context.
You can find the <rsc> node reference on the Assembler References document.
This is a simple text file :
LowRA AS3 Framework
I want to load this file as resource for my application and I don't want to it manually in my source code.
Use <rsc> node for this stuff.
<bean> <rsc id="info" url="myTextFile.txt" /> </bean>
When IoC engine has loaded the file, the content is registered in the BeanFactory with the "info" identifier.
(As IoC ID rules, ID must be unique here too.)
So, to reteive this content in source code, you just
have to use the magic BeanFactory :
var info : String = BeanFactory.getInstance().locate( "info" ) as String; PixlibDebug.DEBUG( "What is it ? + info ); // output : What is it ? LowRA AS3 Framework
All binary file format supported by the Flash player can be loaded as resources.
Loading an image as resource :
<bean> <rsc id="logo" url="myLogo.jpg" type="binary" /> </bean>
Simple. One thing to do, is to defined the type attribute to "binary" ( default is "text" ).
When IoC engine has loaded the file, content will be store on ByteArray format.
Example : SWF Cloning
<bean> <rsc id="footer" url="footer.swf" /> </bean>
var db : ByteArray = BeanFactory.getInstance().locate( "footer" ) as ByteArray; var loader : Loader = new Loader(); loader.x = 0; loader.y = 400; loader.loadBytes( db ); addChild( loader );
Note : can be really useful for content caching too.
In section above, loaded file content are registered in "raw" format.
But we can force the auto deserialization of loaded resource.
First thing to do, import the necessary classes in context to deserialize content.
LowRA offers 3basic deserializers :
To use deserialization, you have to load the dedicated Dynamic Library into context.
For example, the CSSDeserializer :
<bean> <dll url="CSSDeserializerDLL.swf" /> </bean>
Now, the Deserializer class is loaded into application context, and class is available.
Now, we have to specify what kind of deserializer we want to use for specific resource.
Always for a css stylesheet :
<bean> <dll url="CSSDeserializerDLL.swf" /> <rsc id="myStyle" url="styles.css" deserializer-class="com.bourre.encoding.CSSDeserializer" /> </bean>
How it work ?
Just pass the full classpath of the deserializer class you want to use into the deserializer-class attribute.
Behind the scene, when file is loaded, the engine bluid a deserializer instance using this classpath, and deserialize the file content.
Be careful, it is the deserialized content which is registered into BeanFactory. ( raw data is no more available ).
Retreive our CSS Style :
var style : StyleSheet = BeanFactory.getInstance().locate( "myStyle" ) as StyleSheet; var tx : TextField = new TextField(); tx.styleSheet = style; tx.htmlText = "<span class='title'>My title here</span>"; addChild( tx );