Tag Archives: AS3

ActionScript 3.0

How to correct 3-D projection on stage resize

The problem:
You’re using Flash 10’s native 3-D API and notice the projection goes a little skewiff when resizing the window.

The solution:
You need to reset the stage’s projection centre on stage resize, like so…


Embed tag gotchas in Flex SDK 4

In moving to compiling projects with the new Flex SDK 4, I noticed a couple of gotchas to do with the EMBED metatag that I thought I’d share:

Runtime Shared Libraries
If you wish to embed assets in your SWF with the EMBED metatag, so you can manage and update things easily, there’s an extra compiler parameter you must add, in order for your project to compile properly:


This is already added as a new default parameter in FlashDevelop projects. But if you’re planning to build projects from outside a similar IDE, you must add this to your compiler string. Otherwise, the compiler will think you have uninitialised constants and warn you so.

Embedding Fonts
Using the EMBED metatag, or even better runtime loading, for fonts is the sensible way forward. The amount of projects I’ve seen where you need to build from an FLA file full of fonts, which you need to hunt down and install is crazy. With Flex SDK 4, you’ll need to add an extra attribute to your embed tag for fonts, called ’embedAsCFF’:

[Embed(source=’myfont.ttf’, fontName=’MY_FONT’, fontWeight=’regular’, unicodeRange=’U+0020-U+0040,U+0041-U+005A’, mimeType=’application/x-font’, embedAsCFF=’false’)]
public static const MY_FONT :Class;

Happy compiling!

FlashSize – simple browser resizing

How to allow SWFs to display at 100% width/height in your browser – but enforce a minimum width and height, in case of a smaller browser window size than you’ve designed for.

Until recently, I’d used other Flash/browser resize managers when I needed to ensure a SWF is embedded in HTML at 100% width and height, but with support for a minimum width and height setting. But I recently needed a solution the didn’t depend on external JavaScript, due to not having control of the page the SWF is embedded in.

With my simple FlashSize script, all you need do is call:

MouseWheelTrap – how to stop simultaneous Flash / browser scrolling

Update: This project is now hosted at GitHub. There are currently known issues with Chrome’s PPAPI plugin architecture. USE AT YOUR OWN RISK.

I recently stumbled over a new AS3 gotcha that seems to be bugging a lot of the Flash community. Apparently a new ‘feature’ of AS3, whereby using the mousewheel inside an embedded Flash movie still scrolls the surrounding browser window (if it has enough content, that is).

This didn’t happen in AS2. If a Flash movie had focus, mousewheel events weren’t sent to the browser window. It wasn’t a problem in FireFox either, until a recent update and adversely affects any AS3 Flash app embedded in an HTML page where you might want to scroll or zoom with the mousewheel while over the Flash, instead of the scrolling the browser window.

So, I decided to cook up some code to fix this. While it’s early version and isn’t perfect, it suits my purposes, is easy to set up and doesn’t require any external JavaScript – so I’d thought I’d share it with the world, in case Adobe never get around to addressing this ‘feature’.

Introducing MouseWheelTrap. A handy little utility class that traps mousewheel events while the mouse is over the Flash, so your app scrolls how it was intended to. I’ve tested it with SWFObject on PC IE and FireFox, but not with SWFMacMouseWheel on Mac (if someone could tell me if it works). I decided against using jQuery for trapping mouse events, partly out of laziness, partly because many people have no control over the HTML that embeds their Flash app and therefore can’t add custom JavaScript.

Setting up MouseWheelTrap is easy:

  • Download the MouseWheelTrap ZIP package, or just the AS file.
  • Unzip the package and have a look at the demo, or just take the MouseWheelTrap.as file and put it in the com.spikything.utils folder into your own project or classpath.
  • Import the utility and set it up somewhere in your main class like so:

Simple huh? Let me know how you get on…