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="http://www.adobe.com/2006/mxml" layout="vertical" height="600" width="600" horizontalAlign="left">
<mx:ArrayCollection id="blendModes">
<mx:Array>
<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:Array>
</mx:ArrayCollection>
<mx:Canvas height="200" width="400">
<mx:VBox height="100" width="100" backgroundColor="{color1.selectedColor}" backgroundAlpha="1" blendMode="{blendMode1.selectedItem.data}" />
<mx:VBox height="100" width="100" backgroundColor="{color2.selectedColor}" backgroundAlpha="1" x="50" y="50" blendMode="{blendMode2.selectedItem.data}"/>
</mx:Canvas>
<mx:Panel title="Blend Modes" layout="horizontal">
<mx:ComboBox id="blendMode1" dataProvider="{blendModes}" />
<mx:ComboBox id="blendMode2" dataProvider="{blendModes}"/>
</mx:Panel>
<mx:Panel title="Colors">
<mx:ColorPicker id="color1"/>
<mx:ColorPicker id="color2" selectedColor="blue"/>
</mx:Panel>
</mx:Application>


Click here to try the example.

No comments:

 
Software