1////////////////////////////////////////////////////////////////////////////////
2//
3//  ADOBE SYSTEMS INCORPORATED
4//  Copyright 2008 Adobe Systems Incorporated
5//  All Rights Reserved.
6//
7//  NOTICE: Adobe permits you to use, modify, and distribute this file
8//  in accordance with the terms of the license agreement accompanying it.
9//
10////////////////////////////////////////////////////////////////////////////////
11package spark.effects
12{
13import spark.effects.supportClasses.AnimateColorInstance;
14
15import mx.effects.IEffectInstance;
16import mx.styles.StyleManager;
17
18/**
19 *  The AnimateColor effect animates a change in a color property over time, interpolating
20 *  between given from/to color values on a per-channel basis.
21 *  use this effect, rather than the Animate or other effect, when animating color properties.
22 *
23 *  @mxml
24 *
25 *  <p>The <code>&lt;s:AnimateColor&gt;</code> tag
26 *  inherits all of the tag attributes of its superclass,
27 *  and adds the following tag attributes:</p>
28 *
29 *  <pre>
30 *  &lt;s:AnimateColor
31 *    <b>Properties</b>
32 *    id="ID"
33 *    colorFrom="no default"
34 *    colorPropertyName="color"
35 *    colorTo="no default"
36 *  /&gt;
37 *  </pre>
38 *
39 *  @see spark.effects.supportClasses.AnimateColorInstance
40 *
41 *  @includeExample examples/AnimateColorEffectExample.mxml
42 *
43 *  @langversion 3.0
44 *  @playerversion Flash 10
45 *  @playerversion AIR 1.5
46 *  @productversion Flex 4
47 */
48public class AnimateColor extends Animate
49{
50    include "../core/Version.as";
51
52    //--------------------------------------------------------------------------
53    //
54    //  Class constants
55    //
56    //--------------------------------------------------------------------------
57
58    /**
59     *  @private
60     */
61    private static var AFFECTED_PROPERTIES:Array = ["color"];
62    // Some objects have a 'color' style instead
63    private static var RELEVANT_STYLES:Array = ["color"];
64
65    [Inspectable(category="General", format="Color")]
66    /**
67     *  The starting color value.
68     *
69     *  @default 0xFFFFFF
70     *
71     *  @langversion 3.0
72     *  @playerversion Flash 10
73     *  @playerversion AIR 1.5
74     *  @productversion Flex 4
75     */
76    public var colorFrom:uint = StyleManager.NOT_A_COLOR;
77
78    [Inspectable(category="General", format="Color")]
79    /**
80     * The ending color value.
81     *
82     *  @default 0xFFFFFF
83     *
84     *  @langversion 3.0
85     *  @playerversion Flash 10
86     *  @playerversion AIR 1.5
87     *  @productversion Flex 4
88     */
89    public var colorTo:uint = StyleManager.NOT_A_COLOR;
90
91    /**
92     *  The name of the color property on the target object affected
93     *  by this animation.
94     *  A color property is a property that takes 32-bit color value.
95     *
96     *  @default "color"
97     *
98     *  @langversion 3.0
99     *  @playerversion Flash 10
100     *  @playerversion AIR 1.5
101     *  @productversion Flex 4
102     */
103    public var colorPropertyName:String = "color";
104
105    /**
106     *  Constructor.
107     *
108     *  @param target The Object to animate with this effect.
109     *
110     *  @langversion 3.0
111     *  @playerversion Flash 10
112     *  @playerversion AIR 1.5
113     *  @productversion Flex 4
114     */
115    public function AnimateColor(target:Object=null)
116    {
117        super(target);
118        instanceClass = AnimateColorInstance;
119    }
120
121    /**
122     *  @private
123     */
124    override public function getAffectedProperties():Array /* of String */
125    {
126        return (colorPropertyName == "color") ? AFFECTED_PROPERTIES : [colorPropertyName];
127    }
128
129    /**
130     *  @private
131     */
132    override public function get relevantStyles():Array /* of String */
133    {
134        return (colorPropertyName == "color") ? RELEVANT_STYLES : [colorPropertyName];
135    }
136
137    /**
138     *  @private
139     *
140     *  @langversion 3.0
141     *  @playerversion Flash 10
142     *  @playerversion AIR 1.5
143     *  @productversion Flex 4
144     */
145    override protected function initInstance(instance:IEffectInstance):void
146    {
147        super.initInstance(instance);
148
149        var animateColorInstance:AnimateColorInstance = AnimateColorInstance(instance);
150        animateColorInstance.colorFrom = colorFrom;
151        animateColorInstance.colorTo = colorTo;
152        animateColorInstance.colorPropertyName = colorPropertyName;
153    }
154}
155}
156