Sunday, April 22, 2007
Flex SWF files are big, but I like the productivity
My RIA Demo
My first Rich Internet Application (RIA) was created with Flash MX2004. I then converted it to Flash 8. Now I want to build new RIA’s, so I bought Flex Builder 2 which will hopefully help me be more productive. I have been excited about the new way of doing things. I think the biggest advantage will come from the addition of the Sprite object and other more focused visual objects instead of having to use heavy weighted MovieClip’s for everything. Also, all of these visual objects, including the MovieClip, are now created and added to the Stage in a familiar object oriented manner.
One of the hardest things about using Flash to build RIA’s was learning how to take the animation out of the application. It was hard to use the documentation and the help available from the internet because it was usually described in terms of frames. Eventually, I was able to weed through it. I ended up using only 2 or 3 frames to get my application started and otherwise never used a timeline. It looks like ActionScript 3 can be used like a traditional development language and I like that.
We are told Flex 2 applications will run faster due to improved player performance and that never hurts. I really don’t have a problem with my first RIA running too slow after the initial startup and I must have hundreds of little MovieClips that need to be created. I’m even happy with the startup speed but anything less than instantaneous startup could always use improvement. I’m going to put more effort into the startup speed in my next application. I’m thinking I can really make a lot of improvements here especially since I won’t have the overhead of MovieClips and will gain from the reported player improvements.
I got the impression from somewhere in the hype that the compiled code would be more compact but I’m skeptical. My Flash 8 application is currently 68,089 bytes long. I was always amazed at how small it was. I started programming in the early days when program size dominated the architecture. I am probably more attuned to size than most programmers because it is usually not an issue today. Of course there is no doubt that the larger the file, the slower the download. Also, the ISP allows a limited number of bytes per month before surcharges kick in.
I became disappointed immediately after installing Flex Builder 2. I created an MXML project and compiled it with no code added. The size of the SWF file was 125,617 bytes. That was nearly twice as big as my working Flash 8 application. Then I built an ActionScript 3 project with no extra code. The file size was 568 bytes compared to 36 bytes for a Flash 8 file.
The difference between the empty ActionScript 3 and ActionScript 2 SWF files is not a great concern. (That is, unless you need an SWF file that does nothing.) I’m not even sure I would be totally unhappy if I could write the equivalent functionality into an MXML application and it took 68,000 additional bytes on top of the base 125,000 bytes. The start up could actually be faster because of improved performance even though the download would be slower.
Unfortunately, it really does appear that the code grows quickly when using Flex Builder 2 to build either ActionScript 3 or MXML projects. I wrote some ActionScript 3 code to create a Sprite with a rounded rectangular header with gradient fill and a TextField for a title. The size of the SWF is 1179. That means it took 611 bytes for this function along with some test code. Now the source code is relatively concise compared to doing this with Flash 8 and the source code is clean and clear which is wonderful. I haven’t taken the time to build a Flash 8 file to do the same thing. There is a fair amount of code to do just the drawing of a rounded rectangle in ActionScript 2. But I don’t think it would take 611 bytes to do it.
I tried to duplicate a small part of my existing application with MXML and it grew to 283,867 (or 158,250 bytes more) and I admit I didn’t even figure how to do everything with the MXML. Because of this, I’m not sure I’m going to commit to MXML at this point. This is disappointing for at least two reasons. First, I didn’t need to buy Flex Builder 2 to build pure ActionScript 3 applications. Second, my hope of increasing productivity was due partly to being able to use the nice set of GUI controls Flex provides.
At this point, I have a gut feeling that the SWF files are going to be significantly bigger even if I don’t use MXML It may be that I’m not configuring the project correctly. It may be that the end result is still better than before because of speed of execution will compensate for the slower download time. I have seen enough to know that I will be able to develop projects faster and the resulting source code will be easier to maintain but I sure would like to hear some comment about the file sizes.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment