Thursday, July 30, 2009

Adobe Flex: The DisplayObject Blend Mode

The blend mode controls what happens when one display object is on top of another. The default setting in Adobe Flex is that the pixels of a display object override those that are displayed in the background. However you can change this behavior by modifying the blendMode setting. Read the language reference entry for DisplayObject. There you will find a detailed description of each blend mode.
In a nutshell the different blend modes available are:
  • BlendMode.NORMAL

  • BlendMode.LAYER

  • BlendMode.MULTIPLY

  • BlendMode.SCREEN

  • BlendMode.LIGHTEN

  • BlendMode.DARKEN

  • BlendMode.DIFFERENCE

  • BlendMode.DARKEN

  • BlendMode.OVERLAY

  • BlendMode.ADD

  • BlendMode.SUBTRACT

  • BlendMode.INVERT

  • BlendMode.ALPHA

  • BlendMode.ERASE

  • BlendMode.SHADE

Use the following flex code to try the different blend modes:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:core="*" xmlns:mx="" layout="vertical" height="600" width="600" horizontalAlign="left">
<mx:ArrayCollection id="blendModes">
<mx:Object label="Normal" data="normal"/>
<mx:Object label="Layer" data="layer"/>
<mx:Object label="Multiply" data="multiply"/>
<mx:Object label="Screen" data="screen"/>
<mx:Object label="Lighten" data="lighten"/>
<mx:Object label="Darken" data="darken"/>
<mx:Object label="Difference" data="difference"/>
<mx:Object label="Overlay" data="overlay"/>
<mx:Object label="ADD" data="add"/>
<mx:Object label="Subtract" data="subtract"/>
<mx:Object label="Invert" data="invert"/>
<mx:Object label="Alpha" data="alpha"/>
<mx:Object label="Erase" data="erase"/>
<mx:Canvas height="200" width="400">
<mx:VBox height="100" width="100" backgroundColor="{color1.selectedColor}" backgroundAlpha="1" blendMode="{}" />
<mx:VBox height="100" width="100" backgroundColor="{color2.selectedColor}" backgroundAlpha="1" x="50" y="50" blendMode="{}"/>
<mx:Panel title="Blend Modes" layout="horizontal">
<mx:ComboBox id="blendMode1" dataProvider="{blendModes}" />
<mx:ComboBox id="blendMode2" dataProvider="{blendModes}"/>
<mx:Panel title="Colors">
<mx:ColorPicker id="color1"/>
<mx:ColorPicker id="color2" selectedColor="blue"/>

Click here to try the example.

No comments: