O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Flash Hacks
By Sham Bhangal
June 2004
More Info

How do these hacks stand up? Comment on a hack from the book by choosing the associated "Discuss" link below. You can also view the code from any of the hacks by clicking on the "Listing" or "Code" links. A number of hacks have been selected to be featured online in their entirety; you may view those hacks by clicking on the hack titles that are linked.

You can also download all the scripts and other files for this book here.

Jump to: Visual Effects  | Color Effects  | Drawing and Masking  | Animation  | 3D and Physics  | Text  | Sound  | User Interface Elements  | Performance and Optimization  | ActionScript  | Browser Integration  | Security

Visual Effects

HACK
#1

Fake Per-Pixel Transitions
Simulate pixel-based fades and wipes, as supported in Macromedia Director
[Discuss (0) | Link to this hack]

HACK
#2

Per-Pixel Text Effects
Create advanced text effects and transitions that operate on the per-pixel level
[Discuss (0) | Link to this hack]

HACK
#3

Simulate Old Film Grain
Create the effect of old film grain using Photoshop and Flash
[Discuss (0) | Link to this hack]

HACK
#4

Create SWFs from Animated GIFs
Quickly repurpose animated GIFs for use in Flash effects
[Discuss (0) | Link to this hack]

HACK
#5

Animate Photoshop PSD Files with Flash
Import full Photoshop PSD files into Flash, then animate them
[Discuss (0) | Link to this hack]

HACK
#6

A Tree Grows in Brooklyn
Create a random tree generator
[Discuss (0) | Link to this hack]

HACK
#7

Blowin' in the Wind: Simulate Tree Movement
Create forward kinematics with embedded movie clips
[Discuss (0) | Link to this hack]

Color Effects

HACK
#8

Video Color Effects
Simulate a video transition using Flash color effects
[Discuss (1) | Link to this hack]

HACK
#9

Video Fade to Black and Fade to White
Create fade to black and fade to white video transitions
[Discuss (0) | Link to this hack]

HACK
#10

A Custom Color Transform Class
Create a custom class to perform color transformations
[Discuss (0) | Link to this hack]

HACK
#11

Create and Organize Custom Swatches
Save and organize your color swatches without having to use the Color Swatches panel
[Discuss (1) | Link to this hack]

HACK
#12

Borrow Color Schemes from Nature
Sample real-world color to capture natural color combinations and schemes
[Discuss (0) | Link to this hack]

HACK
#13

Simulate Sepia Effects
Simulate hue/saturation effects in Flash to create sepia tone images
[Discuss (0) | Link to this hack]

Drawing and Masking

HACK
#14

Create Filled Circles Quickly at Runtime
Creating filled circles at runtime can be processor-intensive. Draw circles using a single straight line for performance and greater flexibility than author-time drawing allows
The Code
[Discuss (0) | Link to this hack]

HACK
#15

Create Synthetic Art
Instead of downloading large bitmaps or creating predetermined layouts, make Flash generate artwork on the fly

[Discuss (0) | Link to this hack]

HACK
#16

Create Seamless Tiles
Create tiles that mesh seamlessly more easily than you might think. Even nonartists can create repeating tiles using very basic techniques
[Discuss (0) | Link to this hack]

HACK
#17

Fill Areas with Patterns
Flash can't fill a nonrectangular area with a custom tile pattern at runtime. But you can fill any shape with a pattern of custom tiles by using masking
[Discuss (0) | Link to this hack]

HACK
#18

Imitate Escher
Create repeating tiles reminiscent of M.C. Escher's artwork
[Discuss (0) | Link to this hack]

HACK
#19

Fix Alpha Property Inaccuracies
The movie clip alpha property can return inaccurate results. Work around the problem by storing a custom internal alpha-like property, resulting in smoother and more accurate fades
[Discuss (0) | Link to this hack]

HACK
#20

Use Complex Shapes as Masks

[Discuss (0) | Link to this hack]

HACK
#21

Interference Patterns and Ripple Effects

[Discuss (0) | Link to this hack]

HACK
#22

Feather Bitmap Edges
Vectors are great for their smooth edges at any resolution, but sometimes you need to use bitmap art. Improve the apparent quality of a bitmap's edge by cleaning up jaggies via alpha channels or vector edges
[Discuss (0) | Link to this hack]

HACK
#23

Add a Vector Edge to a Bitmap
When you need a graphic that contains textures and a sharp edge, you are stuck. A vector shape will give you the sharp edge but is not able to show complex textures. A bitmap can show complex textures but will have no sharp edge. Create the best of both vectors and bitmaps in Flash—a bitmap with a vector edge
[Discuss (0) | Link to this hack]

HACK
#24

Solve the Bitmap-Shift Bug
In Flash Player 6 and below, bitmap images are displaced and distorted. Place the bitmap at the right location and correct for the distortion in those versions of the Flash Player
[Discuss (0) | Link to this hack]

HACK
#25

A Page-Turn Effect (Exploit Symmetry and Masking)
Create a page-turn animation and other Flash effects with scripted drawing and masks, and by exploiting symmetry
[Discuss (0) | Link to this hack]

Animation

HACK
#26

Smooth Scripted Motion
Increasing the frame rate can cause Flash's rendering engine to hog processor time. Create visually smooth animations without simply increasing the frame rate
[Discuss (0) | Link to this hack]

HACK
#27

Time-Controlled Movement
All scripted subanimations do not need to run at the frame rate. Make a subanimation run at a rate independent of the frame rate by using timed events
The Code
[Discuss (0) | Link to this hack]

HACK
#28

Quick, Bandwidth-Efficient Character Animation
Animating by hand can take ages. Skirt some of the hard work with a few insider tricks from a Disney animator
[Discuss (0) | Link to this hack]

HACK
#29

alt-Flash: Motion Graphics Alternatives
As much as we love Flash, it isn't the only game in town. Create motion graphics with some of the alternatives to Flash
[Discuss (0) | Link to this hack]

HACK
#30

Deja New Animations
Repeating animations are efficient but get dull fast. Create nonrepeating animation cycles to add variety without excessive overhead or resorting to ActionScript
[Discuss (0) | Link to this hack]

HACK
#31

Hacking The Matrix
Quickly re-create the famous falling green text effect from
[Discuss (2) | Link to this hack]

HACK
#32

Computer-Generated Character Animation
If you don't have the time or skill to create character animations by hand, use Curious Labs' Poser application for Flash character animation
[Discuss (0) | Link to this hack]

HACK
#33

Particle Effects
Add realism to any animation using effects with small particles, such as explosions, sparks, rain, or snow
[Discuss (2) | Link to this hack]

HACK
#34

Shape Tweening Complex Shapes
Shape tweening is underutilized due to the difficulty in getting predictable morphs. Create better shape tweens by simplifying your shapes into "single perimeters.
[Discuss (0) | Link to this hack]

3D and Physics

HACK
#35

Simulate 3D
Flash doesn't support true 3D, but you can fake it by arranging 2D image slices as if they are filling a 3D space
[Discuss (0) | Link to this hack]

HACK
#36

Panoramic Images
Use a little ingenuity to create 3D panoramas for playback in Flash, simulating immersion in an environment
[Discuss (0) | Link to this hack]

HACK
#37

An Optimized 3D Plotter
Create a compact and fast 3D engine to plot 3D objects on Flash's 2D Stage
[Discuss (0) | Link to this hack]

HACK
#38

Use Acceleration to Simulate Gravity and Friction
Many real-world phenomena, such as gravity and friction, affect the velocity of objects over time. Model such changes by a simple acceleration equation to create realistic motion under simulated physical conditions
[Discuss (0) | Link to this hack]

HACK
#39

Simulate a Throw
To add a nice touch of realism to your interface, script a throw effect in which an object continues to move in the direction it was released
[Discuss (0) | Link to this hack]

HACK
#40

Detect Multiple Collisions
Collision detection is used in games and simulations. Optimize Flash collision detection to allow advanced motion graphics
[Discuss (0) | Link to this hack]

HACK
#41

Turn Toward a Point
Many games and simulations require the player's ship to rotate toward a point. Use angular motion to turn a sprite so it faces a target
[Discuss (0) | Link to this hack]

Text

HACK
#42

Keep Text Legible
Text legibility varies depending on the font, the point size, and the screen dimensions. Change the font metric on the fly to make the site legible on a variety of screen sizes
[Discuss (0) | Link to this hack]

HACK
#43

Autocomplete Text Fields
Add autocomplete functionality to make Flash complete the data entry for your fill-in text forms
The Code
[Discuss (0) | Link to this hack]

HACK
#44

Store a List of All Input Words
Accumulate a list of popular words for the purposes of searching, indexing, or text autocomplete and store it in a local file
The Code
[Discuss (0) | Link to this hack]

HACK
#45

Import Complex Formatting in Flash
Reproduce complex text/graphic layouts such as mathematic notation in Flash using Microsoft Word as a capture buffer and cleanup tool
[Discuss (0) | Link to this hack]

HACK
#46

HTML and CSS in Flash
Flash MX 2004 offers increased HTML formatting support and adds CSS support. Use them together to create pages that look like Flash but load like traditional HTML pages
[Discuss (0) | Link to this hack]

HACK
#47

Use Accessibility Text as Help Text
Accessibility text is normally used for screen readers for the sight impaired. However, you can also use it as help text for the sighted
The Code
[Discuss (0) | Link to this hack]

HACK
#48

Text Effect Framework
Text effects allow you to animate or present text in interesting ways. Create a general text effect generator with surprising ease
[Discuss (0) | Link to this hack]

HACK
#49

Typewriter Effect
Create the classic typewriter text effect without any manual timeline animation
The Code
[Discuss (0) | Link to this hack]

HACK
#50

Time-Based Text Effects
Create various effects by varying the size and position of letters over time using the text effect framework
The Code
[Discuss (1) | Link to this hack]

HACK
#51

Timeline Text Effects
Some text effects can only be created using shape tweening. Create advanced timeline text effects with the rarely used but invaluable Envelope tool
[Discuss (0) | Link to this hack]

Sound

HACK
#52

Create a Flash Speech Synthesizer
Synthesize speech for added flexibility with reduced bandwidth—no need to record or download predetermined sounds
[Discuss (1) | Link to this hack]

HACK
#53

A Talking, Lip-Synched Avatar
Synchronize an animated head to the speech synthesizer
[Discuss (0) | Link to this hack]

HACK
#54

The Ubiquitous Sound-Kicker Hack
Fix the Flash timeline sound-sync bug
[Discuss (1) | Link to this hack]

HACK
#55

Turn Low-Bandwidth Monaural Sounds into Stereo Sounds
Create stereo sounds without excessive bandwidth by splitting monaural sounds into two channels
[Discuss (0) | Link to this hack]

HACK
#56

Real-Time Sound Effects
Save bandwidth by creating sound effects in real time on the client side. Add reverb and other effects to increase the variety of sounds available
[Discuss (0) | Link to this hack]

HACK
#57

Quickly Create UI Sounds
Create button clicks and UI sounds whether you are nonmusical, busy, lazy, or all three
[Discuss (0) | Link to this hack]

HACK
#58

Optimize Sound
Optimize MP3 sound for Flash
[Discuss (0) | Link to this hack]

HACK
#59

Sound Time Codes (Cue Points)
Associate timecode information with your sound files so Flash can react to your sounds as they play
[Discuss (0) | Link to this hack]

HACK
#60

A Custom Sound Transform Class
Create a custom class to perform sound fades and cross-fades
[Discuss (0) | Link to this hack]

User Interface Elements

HACK
#61

Amit's Dials (Interactive Testing)
User interface elements need not be limited to runtime use for the benefit of end users. Use UI elements during development to test various scenarios quickly
[Discuss (0) | Link to this hack]

HACK
#62

Right and Middle Mouse Buttons
Flash's documented mouse event handlers react to the primary mouse button only. Detect additional mouse buttons with the undocumented ActionScript
[Discuss (0) | Link to this hack]

HACK
#63

Button Movie Clips
Create enhanced Flash buttons using instances of the MovieClip class instead of the Button class
[Discuss (0) | Link to this hack]

HACK
#64

Dude, Where's My Scrollbar?
Create a lightweight scrollbar component for Flash MX 2004
[Discuss (0) | Link to this hack]

Performance and Optimization

HACK
#65

Beat Flash File Bloat
You may find that your FLA gets bigger every time you save it, even if you delete unused assets such as bitmaps and sounds. Beat the bloat with this hack
[Discuss (0) | Link to this hack]

HACK
#66

Bandwidth Testing for Complex Sites
Use WebSpeed Simulator to sidestep the Bandwidth Profiler's inability to simulate bandwidth performance when testing through the browser (i.e., real-world conditions)
[Discuss (0) | Link to this hack]

HACK
#67

Hide Low-Quality Settings
Increase performance and maintain visual appearance by hiding the effects of a reduction in rendering quality
[Discuss (0) | Link to this hack]

HACK
#68

Optimize Graphics for Performance
Graphics can be bandwidth hogs. Optimize graphics for large dividends in overall performance
[Discuss (0) | Link to this hack]

HACK
#69

Benchmark Runtime Performance
The Flash Bandwidth Profiler and third-party tools provide estimates of a Flash project's download time. Benchmark runtime performance to optimize playback as well
[Discuss (0) | Link to this hack]

HACK
#70

Adjust the Animation Complexity Dynamically
Measure the Flash Player's runtime performance in order to adjust the complexity of an effect or animation dynamically to run optimally on both low-end and high-end machines
[Discuss (0) | Link to this hack]

HACK
#71

Performance Budget
A financial budget tells you where you are spending your money. Create a performance budget to understand and adjust where you are expending resources
[Discuss (0) | Link to this hack]

HACK
#72

Substitute Bitmaps for Vectors
Vectors download quickly but can take a long time to render. Use bitmaps instead of vectors to improve playback speed
[Discuss (0) | Link to this hack]

HACK
#73

Optimize Component Downloading and Usage
Flash ships with a large number of components, which are a useful solution to common Flash design tasks. Minimize the considerable download delay they can cause at the start of your SWF
[Discuss (0) | Link to this hack]

ActionScript

HACK
#74

External Script Editors
Flash MX Professional 2004 comes with an editor capable of editing external files, but the standard edition of Flash MX 2004 does not. Increase your productivity with an external editor whether writing ActionScript, JavaScript, XML, or CSS
[Discuss (0) | Link to this hack]

HACK
#75

Strict Typing and Casual Scripters
ActionScript 2.0 introduces strict typing to check for incorrect datatypes. Strict typing can help motion graphics developers spend less time debugging and more time being creative
[Discuss (0) | Link to this hack]

HACK
#76

Code Hints
Flash's Actions panel provides code hints to ease scripting and prevent typographical errors. Take advantage of code hinting without having to name your variables with datatype-specific suffixes
[Discuss (0) | Link to this hack]

HACK
#77

Clone an Object
ActionScript copies objects by reference rather than by value. Clone an object to create an independent copy rather than a reference to the original
[Discuss (0) | Link to this hack]

HACK
#78

An Idle Timer (Timeout Event)
When performance is critical, you don't want to waste processor time checking for user interactivity. Add a "no-interaction" timeout event that does not interfere with performance-sensitive multimedia delivery during periods of interaction
[Discuss (0) | Link to this hack]

HACK
#79

Fast ActionScript Searches
Searching through arrays and text in ActionScript can be slow. Create fast text search code with some string manipulation tricks
[Discuss (0) | Link to this hack]

HACK
#80

Lock the actions Layer
ActionScript can be placed almost anywhere on the timeline. Keep your scripts on a dedicated, locked layer to promote separation of code from assets
[Discuss (0) | Link to this hack]

HACK
#81

Debug with trace( )
The action displays text in the Output panel. Use the action to maximum effect as a debugging tool
[Discuss (0) | Link to this hack]

HACK
#82

Undocumented ActionScript
Everyone likes knowing about undocumented ActionScript. Discover the goodies in the property that Macromedia isn't ready to officially support
[Discuss (0) | Link to this hack]

HACK
#83

ASnative( ) Back Door
All ActionScript method calls are mapped to a table of internal functions built into the Flash Player. Directly access the internal function table via the undocumented method
[Discuss (0) | Link to this hack]

HACK
#84

Obscure Operators
Undocumented ActionScript isn't the only fertile hunting ground for the curious coder. Discover nonobvious uses for several obscure ActionScript operators
[Discuss (0) | Link to this hack]

HACK
#85

Import ASC Files as XML
XML class for basic file loading. Then parse the text out of the single resulting XML node
[Discuss (0) | Link to this hack]

Browser Integration

HACK
#86

Keep Your Site Browser Friendly
The standard Flash site creation workflow does not create the most web- friendly output. Make your designs much more browser friendly with a little HTML hand-editing and web savvy
[Discuss (0) | Link to this hack]

HACK
#87

A Universal Flash Plugin Sniffer
Build a non-JavaScript-based Flash plugin sniffer that won't need to be updated each time Macromedia releases a new version of the Flash Player
[Discuss (0) | Link to this hack]

HACK
#88

Test Multiple Flash Plugins
Test against multiple versions of the Flash Player without moving between computers or having to manually install/uninstall Flash ActiveX or plugin versions
[Discuss (0) | Link to this hack]

HACK
#89

Preferences and Publishing Defaults
Change the Flash IDE defaults to suit current hardware and/or your preferred workflows, plus utilize a few tips and tricks for good measure
[Discuss (0) | Link to this hack]

HACK
#90

Center Your SWF Without Scaling
Center unscaled content in the browser window without using tables or CSS
[Discuss (0) | Link to this hack]

HACK
#91

CSS-Based Browser Centering
Centering an unscaled Flash SWF can inadvertently expose off-stage content. Center a Flash SWF using XHTML and CSS for excellent results without displaying off-stage content and in a standards-compliant way
[Discuss (0) | Link to this hack]

HACK
#92

Dynamically Resize Content
Ideally, your Flash content will display at the desired size even if the user resizes the browser window. Dynamically size your Flash content in response to the browser window to preserve the original design
[Discuss (0) | Link to this hack]

HACK
#93

Create HTML Links in Flash
Flash content doesn't typically include HTML-style links, but there's no reason it can't. Create HTML-style hyperlinks that control the Flash timeline within Flash
[Discuss (0) | Link to this hack]

HACK
#94

Integrate the Back Button with Flash
A long-standing complaint against Flash's usability is that it didn't work with the browser's Back button. Dispel this myth—use the browser Back button to navigate back in a non-timeline-based Flash site
[Discuss (0) | Link to this hack]

HACK
#95

Give the Flash SWF Keyboard Focus
Flash can't detect keystrokes or accept text input unless the SWF has keyboard focus. Force keyboard focus onto your Flash SWF without requiring the user to click manually
[Discuss (0) | Link to this hack]

HACK
#96

Add Key Shortcuts to Your Site
To make your application easier and faster to use (and more like a desktop application), associate a keystroke or key combination with each button in your SWF
[Discuss (0) | Link to this hack]

Security

HACK
#97

Recover Content from a SWF
SWF decompilers can be used to "crack" a SWF file. Use them to recover your own content if you lose the source FLA
[Discuss (0) | Link to this hack]

HACK
#98

Protect and Obfuscate Your Flash Files
Make it difficult for others to steal or reverse-engineer your online Flash content
[Discuss (0) | Link to this hack]

HACK
#99

Make Your SWF Phone Home
Protect your content from being displayed anywhere but on your site—make it location-dependent
[Discuss (0) | Link to this hack]

HACK
#100

Review Compiled ActionScript
Use Flasm to create low-level code optimizations or develop a general optimization-friendly coding style by examining compiled code
[Discuss (0) | Link to this hack]


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.