Table of contents
- How to make your applications smaller and reduce the loading time?
- How to create a swf RSL from a swc and how to use it
- How to reduce the size of any flex app using RSL
- RSL further details
In a previous article I told you about the benefits of RSL’s. But you need also to know how to create them from a swc and how to use them.
First step is to create a new “Flex Library Project”. Write all the code you want to have in it. Then in your main application (or module or where you want to use the library you created) add a reference to that swc. Use the option “Merged into code” for the first stages of development.
Once you are happy with your library (works ok, no more code needs to go in) you need to change how you reference your swc, you need to change the link type to “Runtime shared library (RSL)”.
But RSL will only work (as far as I know it) with swf and you have a swc. So you need to pack your swc as a swf. Here is how to do it:
mxmlc.exe -o=myRSLmodule.swf -file-specs=<an as file form your swc> -source-path=<source path>
an example from one of my modules:
"c:\Program Files\Adobe\Flex Builder 2\Flex SDK 2\bin\mxmlc.exe" -o=d:\work\Flex\qUtils\bin\qUtils.swf -file-specs=d:\work\Flex\qUtils\src\com\qbic\desktop\desktop.as -source-path=d:\work\Flex\qUtils\src
Now you will have 2 files the swc and the swf.
All you have to do is to edit the old reference to the swc:
- go to project properties
- flex build path
- library path
- extend the node that shows your initial reference
- double click on Link type
- change the link type to “Resource shared library (RSL)”
- enter the URL to your swf(yes you need to upload the swf and the swc before you get to this point
) - Un-check the “Auto extract swf to RSL URL” option
- Click on Source Attachement (not double-click)
- click on the remove button
That is it! You now have an RSL included in the project.
Advantages of using RSL:
- Code reuse
- swf that contains the RSL code will be cached by the web-server and by the client browser
- Smaller download size if the application uses several modules that will need some common code (the RSL code)
- Faster download
Dis-advantages:
- Because of the local or network sandbox in flex you will not be able to start your application from local filesystem. You will need to deploy the application
- If you deploy the application keep in mind the security sandbox that can prevent cross-domain scripting (application hosted to a domain and the RSL to another). You can use the crossdomain.xml file to resolve this problem.
- This method is unsupported by ADOBE. It is in fact a hack. The Adobe team is working on improving support for RSL’s in Flex Builder 3.
- If you will host your application on a different server (even on the same server can have this problem) you are open to a man in the middle type attack. Or if someone will hack that server and replace the swf with his own.
Even if there seems less advantages for using this the bandwidth you saved with this method and the smaller loading time of the application will make you choose this approach.
Last word: Once you have finished working on a module or the application I suggest you compile it using the “no debug” option in order to further reduce the size (and also increase the performance) of your application. And yes you can use a RSL build with “no debug” in an application that is compiled with debug turned on (development phase)
compc -debug=false ...
Popularity: 67%
Tags: ActionScript, bug, flex, RSL, tutorial
This post was written by Virgil Cristea
Views: 2276


















