I’ve always liked the effect Windows XP gives you when you select Shut Down… and it then gives you the Shut Down, Restart, Log Off etc options in a modal window. If you leave that window in place for a second or so, your desktop slowly fades to gray while your modal window stays full color. I’ve been wondering for a while whether that effect was possible in Flex.
So, the simple answer is yes. Wait for this example to load, hit the Launch Popup button and watch the background image (you’ll need Flash Player 9).
So, how does it work? Flex 2′s PopUpManager class has an undocumented internal property called modalWindowClass. By setting that property to a class definition of your choosing, an instance of your class is created when you create a modal popup window. This instance sits “behind” your modal popup, affecting the appearance of the application. These windows are often called popup blockers.
I’ve created a popup blocker class (SaturationFadePopUpBlocker) that uses a new SaturationFade effect I’ve also written. The SaturationFade effect changes the color saturation level of component that is the target of the effect using an instance of the Flash Player’s ColorMatrixFilter.
To add the popup blocker to a Flex 2 application is very simple. The following is the single line of code that is required add the above popup blocker effect (alongside the need to import the necessary classes).
PopUpManager.mx_internal::modalWindowClass = SaturationFadePopUpBlocker;
The SaturationFadePopUpBlocker and SaturationFade effect classes can be downloaded as a Compiled SWC (inside this zip) or as a Flex Builder Library Project. The Library Project includes the compiled SWC and all the source code.
Although this example fades the background to gray, the SatuationFade effect I have written lets you change the color saturation of a component to any level, including making it brighter. The start and end saturation levels, along with the duration of the saturation fade, are all customisable in the Saturation effect and SaturationFadePopUpBlocker classes.
The SaturationFade effect class can also be used as a standalone effect, in place of any of the existing Flex framework effect classes. In this example, the SaturationFade effect plays when you hold your mouse down over the image, with the color saturation level fading from 1 to 0. The saturation level animates back to 1 when you let the mouse go:
The code for the above example is:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:eff="com.adobe.effects.*" > <mx:Script> <![CDATA[ import com.adobe.effects.SaturationFade; ]]> </mx:Script> <eff:SaturationFade id="fadeToGray" duration="500" saturationFrom="1" saturationTo="0" /> <eff:SaturationFade id="fadeBack" duration="500" saturationFrom="0" saturationTo="1" /> <mx:Image mouseDownEffect="fadeToGray" mouseUpEffect="fadeBack" source="sunset.jpg" /> </mx:Application>
I won’t go into detail about the implementation of the classes for now. The SaturationFadePopUpBlocker class is very small and should be fairly self-explanatory to most people. If there’s a demand, I’ll do a future post about creating effects using the Flex effects framework and, in particular, how the SaturationFade effect works.

I rikey rots
A true queenslander comment
Hope you don’t mind but I copied your example in Flash 8 on my blog – gave you props for the idea. Nice work. Check it out:
http://pixelfumes.blogspot.com/2006/09/flash-8-version-of-modal-pop-up.html
-Sarge
Can you give an example, where to put line
PopUpManager.mx_internal::modalWindowClass = SaturationFadePopUpBlocker;
Thanks in advance!
Hi Andrey,
Putting that line in the creationComplete handler of your main application should suffice.
Ali
Thanks! I was creating a non-modal window and that’s was my fault:)
Great technique. Thanks for creating this.
One thing i observed is that the window is not modal anymore, i can push the buttons behind it although they are black and white, using the swc. Is there any setting i can set to prevent this and make the popup act like a true modal window?
Thanks for this great example
Guillermo, I’ve found a way:
In SaturationFadePopUpBlocker.as change overriden method createChildren.
there’s a code:
protected override function createChildren():void
{
super.createChildren();
modalWindow = new FlexSprite();
modalWindow.name = “modalWindow”;
var sm : ISystemManager = (parent is SystemManager)
? (parent as SystemManager)
: null;
addChild((modalWindow as DisplayObject));
var g : Graphics = modalWindow.graphics;
var s : Rectangle = sm ? sm.screen : new Rectangle(0,0,100,100);
g.beginFill(0xFFFFFF, 0.0);
g.drawRect(0,0,1,1);
g.endFill();
modalWindow.width = s.width;
modalWindow.height = s.height;
modalWindow.x = s.x;
modalWindow.y = s.y;
originalFilters = parentApplication.filters;
effect = new SaturationFade( parentApplication );
effect.duration = FADE_DURATION;
effect.saturationFrom = SATURATION_FROM;
effect.saturationTo = SATURATION_TO;
effect.play();
}
and that’s all.
But there’s a problem I don’t know how to fix: when I try to launch a popup it’s ok, but then I try to run another popup from this current popup, after close first popup, effect doesn’t work correctly
The “PopUpManager.mx_internal::modalWindowClass” property doesn’t seem to be available with the new 2.0.1 version of Flex Builder. Does this have anything to do with the mx_internal namespace?
For Flex 2.0.1 in the SaturationFade.as file, I had to change all references of “EffectInstance” to “IEffectInstance”–including the import statement and the initInstance method signature.
For Flex 2.0.1 PopupManager is not a class within itself. It’s a wrapper onto a Singleton of type IPopUpManager
You get it like this before your init function:
private static var ipum:IPopUpManager = Singleton.getInstance(“mx.managers::IPopUpManager”) as IPopUpManager;
and then in creationComplete you use:
ipum.mx_internal::modalWindowClass = SaturationFadePopUpBlocker;
also in the function above, modalFunction needs to be declared as FlexSprite before use.
Alistair,
Any word on the flex calendar release ? I’m in desperate need for a project.
Hi Andrey,
Putting that line in the creationComplete handler of your main application should suffice.
One thing i observed is that the window is not modal anymore, i can push the buttons behind it although they are black and white, using the swc. Is there any setting i can set to prevent this and make the popup act like a true modal window?
Thanks for this great example
The “PopUpManager.mx_internal::modalWindowClass” property doesn’t seem to be available with the new 2.0.1 version of Flex Builder. Does this have anything to do with the mx_internal namespace?
Is it possible to post a new version of this nice effect? With all the fixes mentioned here I still have runtime problems.
is Fade to Gray Modal Window Flex Effect an adobe photoshop plug-in ?
modalFunction needs to be declared as FlexSprite before use.
“So, the simple answer is yes. Wait for this example to load, hit the Launch Popup button and watch the background image (you’ll need Flash Player 9).” but how
Any word on the flex calendar release ? I’m in desperate need for a project. thanks for all!!
Hi,
very nice, but i didn’t succeed in make it run with Flex3/Apollo. Anyone has a full working example ?
Thanks,
Cyril
For Flex 2.0.1 in the SaturationFade.as file, I had to change all references of “EffectInstance” to “IEffectInstance”–including the import statement and the initInstance method signature.
One thing i observed is that the window is not modal anymore, i can push the buttons behind it although they are black and white, using the swc.
I’ve put together a quick example on: http://www.rachaelandtom.info/node/1461
I am also interested in the calendar feature and thank you a lot for this effect.
Nice work! What code do you use to close the smaller form when you hit the “x” on the form?
Thanks in advance
is there a zip file of the whole modal app? As a new Flex student, I still get pretty lost. Or if someone can put the entire code for the App that makes the pop up window appear and the background go gray, that would be awesome, please.
Cordially,
Abel K.
Miami Beach, FL
What code do you use to close the smaller can put the entire code for the App that makes the pop
Nice work..
saturationTo=”1″ or saturationTo=”2″ good working..
you should enable “view source” code on example projects…
For Flex 2.0.1 PopupManager is not a class within itself. It’s a wrapper onto a Singleton of type IPopUpManager
You get it like this before your init function:
private static var ipum:IPopUpManager = Singleton.getInstance(“mx.managers::IPopUpManager”) as
you should enable “view source” code on example projects
You get it like this before your init function:
private static var ipum:IPopUpManager = Singleton.getInstance(“mx.managers::IPopUpManager”) as
Alistair,
Any word on the flex calendar release ? I’m in desperate need for a project.
The “PopUpManager.mx_internal::modalWindowClass” property doesn’t seem to be available with the new 2.0.1 version of Flex Builder. Does this have anything to do with the mx_internal namespace?
could u send modal page(form) sample which is working correctlly
The “PopUpManager.mx_internal::modalWindowClass” property doesn’t seem to be available with the new 2.0.1 version of Flex Builder. Does this have anything to do with the mx_internal namespace?
flex 2.0.1 solution:
uncheck the project’s compiler ‘enable strict type checking’
then
var ipm:IPopUpManager =Singleton.getInstance(“mx.managers::IPopUpManager”) as IPopUpManager;
ipm.mx_internal::modalWindowClass=SaturationFadePopUpBlocker;
I found a small issue if you load a popup right after closing a popup – seems the new popup takes the de-saturated filter as the “originalfilter”, so when you close the new popup – it reverts to, you guessed it: the desaturated filter.
The crappy fix I made is to change “parentApplication.filters = originalfilters” to “parentApplication.filters = new Array()” which just erases the filters.
The better fix would be to check for the instance of a SaturationFade filter and remove it from the array of originalfilters..
anyway, nice little class – for those of you having trouble getting it to work in flex builder 3, be sure to follow clshrock’s post about using the Singleton wrapper with the IPopUpManger object.
Putting that line in the creationComplete handler of your main application should suffice.
+1
Hi,
Putting that line in the creationComplete handler of your main application should suffice.
TgrL
What code do you use to close the smaller form when you hit the “x” on the form
One thing i observed is that the window is not modal anymore, i can push the buttons behind it although they are black and white, using the swc.
you should enable “view source” code on example projects
you should enable “view source” code on example projects…
you should enable view source code on example projects
thanks
Thanks! I was creating a non-modal window and that’s was my fault:)
What code do you use to close the smaller can put the entire code for the App that makes the pop
Any word on the flex calendar release ?
The “PopUpManager.mx_internal::modalWindowClass” property doesn’t seem to be available with the new 2.0.1 version of Flex Builder. Does this have anything to do with the mx_internal namespace?
Any word on the flex calendar release ? I’m in desperate need for a project.
For Flex Builder 3 you can write also
import mx.core.Singleton;
import mx.managers.*
…..
var ipm:IPopUpManager = Singleton.getInstance(“mx.managers::IPopUpManager”) as IPopUpManager;
var o:Object = ipm;
var p:QName = new QName(mx_internal, “modalWindowClass”);
o[p] = SaturationFadePopUpBlocker;
Any word on the flex calendar release ?
Putting that line in the creationComplete handler of your main application should suffice.
Thanks! I was creating a non-modal window and that’s was my fault:)
Can you give an example, where to put line
PopUpManager.mx_internal::modalWindowClass = SaturationFadePopUpBlocker;
Thanks in advance!
Thanks! I was creating a non-modal window and that’s was my fault:)