Monday, May 25, 2009

Difference between .as, .fla and .swf files

Really quickly I want to talk about the simple differences between an ActionScript file (*.as), a Flash File (*.fla) and a Shockwave File (*.swf) pronounced swift file.

Flash files are workspace files that use .fla extension and contain the timeline, stage, library and assets which can contain any number of movieclips (symbols), sound files and graphics: it's your project's development environment. (I hesitate to use the word 'project' because flash also has something called .flp, Flash Project that is for bigger projects containing more than one .fla file and other files, but I haven't gotten to that yet)

SWF files are the compiled executables you get when you export movie from your .fla file. Not all the assets and components in your .fla are exported into your .swf, only those that are actually used. SWF files are what you actually distribute on the net (or whereever) for the world to see. They are the files you embed in your HTML (for a website for example).

.as (actionscript) files are pure class definitions that can be included into fla files to create objects with. Hence Actionscript files define objects that may be used repeatedly in different .fla projects. Each .as file contains only one class definition. The class name must also be the name of the actionscript file. The class definition must be wrapped in a package declaration (you can name the package to avoid name space collisions of class names, I think that is what flash uses itself for package names like flash.display.MovieClip etc), or you can just leave package name blank for small projects, it works for now.

Incidentally, The fla project automatically has access to any actionscript files saved in the same directory as itself. It is also possible to load classes that are in a shared directory above the fla directory through classpath settings (publish settings > flash > actionscript settings or preferences > actionscript > actionscript 3 settings ... something like that, I haven't tried it). (Note to self: I moved Ball.as up two directories to see if the .fla compiler would complain that it couldn't find Ball.as, but it did not complain! Maybe it's somehow linked already and knows where I move it? Not sure...)

One fla project can load one main .as file by selecting the document class in the property inspector of the project (click on an empty area of the stage if your property inspector is not showing it -- or I think you can get to it through publish settings). That calls the constructor function of the class defined in the .as file.

So in a nut shell that's what those different files are for.

No comments:

Post a Comment