“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

Reading Zip files with Actionscript 3

Posted: September 24th, 2007 | Author: Tiago Bilou | Filed under: Actionscript3, Code, Tutorial | 6 Comments »

Last week, while developing an actionscript application, we had the need to read files stored inside a zip file. Our first approach was to use Zinc to deflate the zip file into a temporary directory.

Because some problems arouse with ZINC I took sometime to read about this AS3 Zip Library As it turns out it does a great job and reading and building zip files and it's really easy to use. Make sure you download and install the Library.

After playing around with this Library for a while I wanted to display some images I had inside the zip file. The issue was how to convert a ByteArry into a BitmapData. It took me a while to figure it out , but as it turns out it's really easy.


Instantiate classes by name

Posted: September 14th, 2007 | Author: Tiago Bilou | Filed under: Actionscript3, Code, Tutorial | No Comments »

A couple of months ago I wanted to instantiate classes based on their name at runtime, using Flex Builder. At the time I read about the method getDefinitionByName. Everytime I tried to use it I got the error

Error #1009: Cannot access a property or method of a null object reference.   

I googled about it and found Daniel R. post on the subject. According to him

"The problem seems to be that if the runtime module makes a side-effect reference to a component, which is not included in the main application, it never really gets included in the SWF and as such causes problems when accessed"   

And his solution was to declare a static instance of the class you wanted to instantiate at runtime.

private static const classInstance:ClassToInstantiate = null;   

This *fix* becomes a problem when you have many classes to instantiate and have to declare an instante for each one. If the classes you want to instantiate are in the flash library (movieclips), there is a workaround for the problem described above.

  • When you export the Flash library, remember to check the "Export SWC".
  • Make sure you include the SWC in the Flex Builder.
  • (Here's the Magic) Just use this arguments in the compiler options:

-include-libraries $PATH_TO_SWC/LIBRARYNAME.swcÂ