17/09/2010

reducing the size of a Flex movie - part 2

By using the ItDepends app, I mentioned in a earlier post, I decided that I'd try re-writing my app so that it loads the Financial Price data.

Originally I was making a HTTPService call to as ASPX page, then to keep the data up to date I created a timer that repeated this HTTPService call every few seconds.

Through looking at the link report I generated through Flex Builder for the project I noticed that a larger percentage of the app's dependency was in this loading of data.

As I was just loading a string from this ASPX page I decided to try another method. So I wrote a new TimerSevice class, that used the URLLoader/URLRequest classes to access the ASPX page and load data from the page. By using the Injection functionality that RobotLegs provides it was easy to switch out the old HTTPService version with the new URLLoader version.

By writing a Interface that both service classes implemented I was able to set in the context class

injector.mapSingletonOf( ITimerService, TimerURLLoaderService );

Then when I generated a release build of the application and compared the file size of the generated swf to the previous version. I found that it reduced the size of the SWF by 50K. That is quiet a reduction in size.

I'm not sure if this reduction is due to how the HTTPService class has been written compared to the URLLoader class, or that the HTTPService class does a lot more than the URLLoader class, and that I was using a class that had far more functionality than I needed. And the app was carrying this extra baggage.

No comments: