We will need to fade our applications background color from one value to the next like 0xC58D31 to 0×87FEE9. Fading the background color of an element means that you gradually change that element’s background color from one color to another. This effect is useful for many things especially when we update a web page without reloading it because it gives you a way to draw attention to the area of the web page that has been updated so the user doesn’t miss it.It is not difficult for DHTML or JavaScript, but how to do it in Flex? The following shows how to make the background of your pages fade from one color to another in flex.
( Project Source File Struct)
Source Code:
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" viewSourceURL="srcview/index.html">
- <!--
- The animate color effect that takes a from value, to value, and a duration
- and smoothly transitions the color values in between.
- -->
- <ds:AnimateColor xmlns:ds="com.effects.*"
- id="fadeColor"
- target="{box}"
- property="backgroundColor" isStyle="true"
- fromValue="{startColor.selectedColor}"
- toValue="{stopColor.selectedColor}"
- duration="4000" />
- <mx:Panel title="Animate Color Demo" width="100%" height="100%"
- paddingLeft="5" paddingRight="5" paddingBottom="5" paddingTop="5">
- <mx:HBox verticalAlign="middle">
- <mx:Label text="Start Color:" />
- <mx:ColorPicker id="startColor" selectedColor="0xC47D31" />
- <mx:Spacer width="10" />
- <mx:Label text="Stop Color:" />
- <mx:ColorPicker id="stopColor" selectedColor="0x67DEF9" />
- <mx:Spacer width="10" />
- <mx:Button label="Go!" click="fadeColor.play();" />
- </mx:HBox>
- <mx:VBox width="100%" height="100%" id="box" borderStyle="solid"/>
- </mx:Panel>
- </mx:Application>

June 22nd, 2008
Ntt.cc 








Posted in
Tags: 
RSS Feed
Email Feed
[...] 本文和代码全部来自http://ntt.cc/2008/06/22/fade-from-one-color-to-another-animating-color-transitions-in-flex.html [...]
Great stuff!
One question though, how to do make it so it fades to nothing? so it actually just fades out?
Nevermind – resolved with mx:fade
Very elegant implementation – thanks!
Really a nice implementation. Thanks for making it available.
Good post – a good resource I came accross. I would like to suggest an photo effect program somehow related.