ChrisInch.com

Innovation, practicality and creativity

Blocking Backgrounds in Flash

Posted by Chris Inch on Feb. 12th, 2006

A very common problem in Flash is as follows:

Your stage is covered in buttons and interactive movie clips and you want to put something on top of your entire stage and disable all the elements in the background all at once.

For example, you might be making an app with lots of text input fields and buttons. Let's say you wanted to pop up a warning message on top of the screen to warn the user about something. Doing so, you want all the buttons in the background to be disabled.

Here's a simple method to accomplish that task...

  1. Make a completely transparent rectangle the same size as your stage on the layer above everything that you want to block.

  2. Convert this rectangle to a Movie Clip.

  3. Give this Movie Clip instance a name of "blocker".

  4. In the frame that the movie clip appears, write the following ActionScript:

Actionscript:

this["blocker"].onRelease = function() { };
this["blocker"].enabled = false;

Doing this creates a movie clip which has an "onRelease" action assigned to it. Even though we've assigned no code to the onRelease function, Flash still sets up the Movie Clip to be clickable. The second line of code disables the clip so that it isn't clickable. By doing so, you successfully block everything beneath the clip. Voila!

Comments

#1 Pablo S. commented on May 8th, 2006 at 4:05 a.m.:

THANK YOU SO MUCH FOR THIS!!

#2 inch commented on Aug. 16th, 2006 at 9:38 a.m.:

No problem. Glad I could help!

#3 inch commented on Aug. 31st, 2007 at 8:46 a.m.:


I wanted to add a comment here to let people know that this article really only refers to versions of flash earlier than Flash 9 and ActionScript 3.0. If you're experiencing problems not being able to click through the top movie clips, please see my article on Un-blocking backgrounds in Flash.

#4 listel commented on April 6th, 2011 at 8:24 p.m.:

Thanks to me too!

Post a comment

Chris Inch is a programmer, web developer, musician, graphic designer, photographer and handyman from Ottawa, Ontario, Canada. Chris graduated from the University of Waterloo in 2004 with a degree in Computer Science. He currently works professionally as an ActionScript 3.0 developer.

Links

Recent Blog Post

Being more productive in 5 easy steps
Posted by Chris Inch on April 17th, 2011

Tags

Misc, SEO, Flash, ActionScript, OpenID, Life, Games, HTML, Money, Tips, CSS, Sites, Python, Django, Shaving, Handyman, Design, Wushu, Complaints, Regex, Moleskine, DIY, Photography, Wedding, Food, Recipe, Pranks

RSS Feeds