Anti-alias when scaling images and video in Flash

Here’s one of those tips that you stumble upon, and feel embarrassed that you didn’t know this years ago.

Notice when scaling a bitmap or video up and down the image is subject to serious aliasing. Especially with a transparent background. Everything looks pixelated and choppy. Right?

Here’s the solution. In the properties of your image in the Flash library you will see the following setting.

Smoothing

Note that “Allow smoothing” is checked. This allows Flash to re-sample the image when it is scaled up or down, naturally there is some quality  loss but essentially it solves your problem. Used sparingly it may help with your bitmap manipulation.

What about video? No problem. The same principle applies, but you have to use ActionScript.

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);

myVideo.attachVideo(ns);
ns.setBufferTime(0);
ns.play(“mymovie.flv”);
myVideo.smoothing=true;

The last line is the killer!

Seamless Flash audio loops.

Here’s a tricky little issue that I’m sure a few of you Flashers have come across on your travels.

Problem: You have an audio loop, like a clock ticking. You produce a perfect loop in your sound editor of choice and export it out as an MP3. You then import the sound onto your timeline in Flash and no matter what you do, you can’t get it to loop properly. It’s as if Flash has somehow added a fraction of a second of silence to the start and end of the sound clip, making it impossible to loop seamlessly.

Solution: Export a wave file instead of an MP3 – Not sure why, but MP3s behave differently to wave files in Flash. Wave files loop perfectly. Don’t worry about compression because there’s an MP3 compression option inside Flash anyway, so you still get the compression benefits that the MP3 format has to offer without the loop problems. Loop perfection!

Masks in Flash

Ever tried to animate the masking of multiple areas of an image and found that everything goes wrong?

Well here’s a simple tip.

Flash hates a mask that’s in pieces. Sometimes it’s fine but sometimes it messes up, for example if you have an animation of eyes blinking, using masks to hide / show the pupils, either use one mask that is connected out of the area of interest or two separate masks for each eye.

Note: Beware of strokes or the remains of partially deleted strokes in masks. Select the entire mask frame and switch of all strokes from the selected vectors to ensure that those pesky bits of corners or minuscule remnants don’t get in the way of your masking genius!

Default Publish Settings – SwfObject

It’s been bugging me for a while that I can export HTML with the AC_RunActiveContent.js embedding method directly from Flash CS3. I can replace the RunActiveContent HTML with a SwfObject Template but I can’t get the Flash IDE to export a copy of the swfObject.js file.

Here’s the solution.

Navigate to:

Library>Application Support>Abode>CS3>en>configuration>HTML>Active Content Files
Backup AC_RunActiveContent.js by renaming it or moving it somewhere else. Paste in a copy of the latest swfobject.js and rename it AC_RunActiveContent.js.

Annoying that it has to be called something else, so I add the following comment after the tag:

//re-named swfObject default export

I’d love to find out how I can use swfObject without having to rename it first.

Pixel Aspect Ratio (PAR)

I had an unpleasant experience recently with a director who told me too late that the fine composition I’d done was too small.

I’d worked to 1024×576 (SD) but he’d filmed in 1920×1080 (HD)

Here’s some info about how to manage this kind of problem – thanks to Artbeats for two very useful PDFs

Because video often uses rectangular pixels and computer monitors use square ones circles and peoples faces look fatter on your monitor in NTSC and skinny in PAL.

In After Effects there are two places where you need to set the pixel aspect ratio: for the source, and for the composition where you are combining layers. To set the pixel aspect ratio (PAR) for a source, select it in the After Effects Project panel, and type Command+F on Mac (Control+F on Windows) to open the Interpret Footage panel. In the Other Options section is a popup for Pixel Aspect Ratio: Set it to match the format of your source. After Effects does a reasonably good job at auto-sensing the correct PAR for a footage item when you import it, but it is always good to double-check this popup – especially when using widescreen footage.

To set PAR for a composition in After Effects, select the comp and type Command+K (Control+K) to open the Composition Settings dialog. It too has a Pixel Aspect Ratio popup; set it to match your intended output format. This happens automatically when you pick a Preset in the Composition Settings, but is easy to miss when you manually set up a comp. As long as you set the PAR popups for every footage item and composition correctly, programs like After Effects will then know which images to stretch and which to squash to correct everything as needed for your final video.

A NOTE ON PHOTOSHOP

You may know that there is an option in Photoshop to change PAR to rectangular. This is not advised because changing the PAR tag on a file does not re-scale an image; it just changes the tag! To give an example: If your photo started out with square pixels, changing the PAR tag to DV will not give your photo non-square pixels – it will just give your photo an incorrect tag.
Therefore, many advise creating all of your non-video elements using square pixels. Rather than try to match any particular size, the safest approach is create the element 25–100% larger than you need it to be; that way, you can also scale it down or reposition it as needed in your video program.

pixel-aspect-ratios

If you create still images at these sizes, and tag them as having square pixels in a program like After Effects, After Effects will automatically adjust them to be the same size as their corresponding video frame.

Hope that helps!

TextMate for ActionScript

Wow! I’ve been exploring the various features of TextMate and how it’s use relates to Flash / ActionScript development. There are some great built in features and lively communities offering excellent bundles for extending TextMate.

Here’s how I set it all up.

Essentially you install the ActionScript bundle and use the Bundle Editor to point everything in the proper direction.

class test {
function test() {
// Empty constructor
}
// Hook for MTASC. This method will be called to start the application
static function main() {
var myVar:String;
myVar=” Patrick”
_root.createTextField(“hello_txt”,1,0,0,800,30);
_root.hello_txt.text = “Hello, World!”+myVar;
_root.Button1._alpha=50;
_root.Button1.onRelease = function(){
_root.Button1._alpha=100;
trace(“Hello World!”);
}
}
};

I copied the above .as file from the one that’s automatically generated by selecting file>New from template>ActionScript>MTASC sample and fiddled with it.

If you stick a .yaml file in the same directory as your .as and .swf file you can pass parameters to your preview like, trace, in my case through console, and the SWF header.

——————

# Name of your output file:
swf: test.swf

# Name of your main class:
app: test.as

# Folder/URL/file to open when compilation succeeds. Use ‘textmate’ to preview in TextMate:
preview: textmate

# SWF Header:
player: 8
width: 800
height: 600
fps: 31
bgcolor: 000000

# Optional, use it to send additional MTASC parameters (i.e: -strict)
params: -main -mx

# If you want to use Console.app (see )
trace: console

——————

Blogging from TextMate

This is my first Blog, posted directly from within TextMate.

Wow! What a cool feature. It’s easy to set up, simply, do the following:

Bundles>Blogging>Setup Blogs

Enter your blogs URL, username and password and that’s it. Then all you need to do is write your post and publish.

Bundles>Blogging>Post to Blog

TextMate will prompt you to enter a post title and your username, then publish whatever you’ve written.

How cool is that?

Apparently you can even add images.

Exporting Flash Movies to other formats

Just a quick one for those of you pulling your hair out. Movie clip animations don’t work when exporting Flash to other formats or importing .swfs into external applications, like Quick Time, After Effects or image sequences.

Movie clips themselves are fine, but they only display the first frame. The secret is to convert all your movie clips to graphic symbols! They work just fine. If you scrub the play head through your timeline, whatever you see will probably render okay elsewhere.

If you are creating a Flash Banner and want to export frames to animated gifs it is a good idea to build your animation entirely on the root timeline, or use graphic symbols. It will save you a lot of hassle later.

Managing bitmap compositions in Flash.

Imagine you have a Flash website that makes use of hundreds of images that need to be regularly updated. Picture a virtual shop with a range of garments that need to updated seasonally. There are essentially three ways to help us manage these updates. That may be combined, extended and varied according to the needs of the specific project.

  1. Content management system that allows administrators to select a garment from a list of thumbnails and upload another image to replace it,
  2. Manually enter the Flash movie and import each new image and swap the old bitmaps for the new ones.
  3. Externally loaded images that can be switched by swapping the old images with the new in a central image repository directory.

At first glance most developers would rule out option 2 but when combined with bitmap fills, a very powerful means of organising, exactly positioned, multiple bitmaps is revealed.

Take the following PNGs

Test1
Test2a
Test2b
Test2c

So we can load one image into Flash that contains all the data of any number of separate bitmaps. Select the bitmap on the stage in Flash and Modify>Break Apart. You may now use the lasso tool to select regions of the bitmap and save them off as individual symbols. Positioning them within your “virtual shop” as required.

So what? Well the clever bit comes when you need to update the images. All you need to do is open the main bitmap .psd in photoshop and edit away, hundred of images may be swapped out and replaced etc. If you’re sensible and set up your original document with crop marks and guides, you can maintain absolute control over each symbol in Flash when you come to update the bitmap in the Library.

Once you’ve saved off your new image, select your bitmap in the Flash Library > right click >select Properties>Update. Flash with automatically replace the main image with the new one (if saved with the exact name and in the same location as the original) or allow you to navigate to another location to select the new bitmap.

Once this is done, not only will the main bitmap be updated, but so too with all the 100s of symbols you created with the lasso tool earlier. Magic!

ADDITIONAL NOTES:

There is a variation of this idea which may be a possible combination of options 2 and 3, using the beginBitmapFill function. The idea being, you import your original image lasso it into multiple symbols, position itcorrectly on your stage, then import the latest version of the bitmap via actionscript to replace the bitmapFill dymanically, meaning you don’t even need to open Flash anymore.

Note to self – when you have a moment check this out.