2006-06-05

AS to outline your Flash movie…

With so much to do during the day it is always best to streamline production to work more effectively. A lot of the Flash work I am called upon to develop is online marketing materials (read: banners). These pieces always have a definite set of parameters to run at the publisher's sites. One requirement is that all banner advertisements need an outline. I used to always create this within Flash, converting it to a symbol that I could cut and paste between files.

ActionScript, however, is a wonderful programming language that I am learning more about everyday, can do this for us. One of the simpler concepts is that ActionScript can draw elements based around parameters that are defined within the code. Here is the code I have begun using to create an outline around my .swf files.

/*1px stroke outline */
Stage.scaleMode = "exactFit";

var stroke:MovieClip = _root.createEmptyMovieClip("stroke", 1000);
stroke.lineStyle(1, 0x000000, 100);
stroke.moveTo(0,0);
stroke.lineTo(0, Stage.height-1);
stroke.lineTo(Stage.width-1, Stage.height-1);
stroke.lineTo(Stage.width-1, 0);
stroke.lineTo(0, 0);

To use this code, create a new ActionScript document and paste the above code into the panel. Save the .as file as something obvious that you can keep in a library of frequently used code snippets. Now whenever you create a new Flash document, call that .as file in the first lines of your new Flash document to have a 1 pixel border wrapping your published .swf.

It is quick, lightweight and reusable. Portable code combined with a library of commonly used assets has helped greatly in decreasing production time while increasing efficiency. I hope you can find some use for this.

No comments: