/////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010, Blogagic (http://blogagic.com/) // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // - Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. // - Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other materials // provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /////////////////////////////////////////////////////////////////////////////////////////////////////// /* EditInPlaceEffect - Animate alpha of a component between read, focus and edit states. Copyright (C) 2010 Blogagic (http://blogagic.com/) Version 0.1 EditInPlaceEffect changes the alpha of a component based on its state: read, focus or edit. By default (read mode), the component alpha is set to 0 "hiding" all styles applied to the component (i.e. no background color, no border, etc). The component is more or less, transparent. When the mouse hovers over the component, the alpha is changed to 0.3 making the styling options appear and (hopefully) letting the user know that it can be edited. When the component gains focus, the alpha is set to 1.0 making all styling options fully visible (i.e. include the component background color). When the component loses focus, its alpha is reset to 0 either immediately or by using a smooth fading effect if the value controlled by the component has been changed during the edition phase. EditInPlaceEffect can be associated to any UIComponent as long as it has a String property providing the value for comparison. When the effect is executed, it just registers some event listeners to manage the "real" effects. Indeed, this effect is supposed to be applied to creationComplete event (for example) just as a registration step for further events/processing. Licensed under the Creative Commons BSD Licence http://creativecommons.org/licenses/BSD/ */ package com.blogagic.effects { import com.blogagic.effects.effectClasses.EditInPlaceEffectInstance; import mx.core.UIComponent; import mx.effects.Effect; import mx.effects.IEffectInstance; /** * The EditInPlaceEffect changes the alpha of a component based on its state: read, focus or edit. * *

By default (read mode), the component alpha is set to 0 "hiding" all styles applied to * the component (i.e. no background color, no border, etc). The component is more or less, transparent.

* *

When the mouse hovers over the component, the alpha is changed to 0.3 making the styling * options appear and (hopefully) letting the user know that it can be edited.

*

When the component gains focus, the alpha is set to 1.0 making all styling options fully * visible (i.e. including the component background color).

*

When the component loses focus, its alpha is reset to 0 either immediately or by using a * smooth fading effect if the value controlled by the component has been changed during the edition phase.

* *

EditInPlaceEffect can be associated to any UIComponent as long as the component has a String * property providing the value for comparison.

* * EditInPlaceEffectInstance must not be used directly; it is created by EditInPlaceEffect. * * @mxml * *

The <mx:EditInPlaceEffect> tag supports the following tag * attributes:

* *
	 *  <mx:EditInPlaceEffect
	 *    Properties
	 *    textProperty="text"
	 *    alphaRead="0.0"
	 * 	  alphaFocus="0.3"
	 *    alphaEdit="1.0"
	 *  />
	 *  
* */ public class EditInPlaceEffect extends Effect { //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- /** * Specifies property name of a String property of the monitored component. * The property value is stored when focus is gained by the monitored component; * on focus out, it is compared with the current property value and, if * different, the fading effect is triggered. * * @default text */ [Bindable] public var textProperty:String = "text"; /** * Specifies the alpha value applied to the component when it doesn't have focus and * mouse isn't hovering over it. * * @default 0.0 */ [Bindable] public var alphaRead:Number = 0.0; /** * Specifies the alpha value applied to the component when it has the focus. * * @default 1.0 */ [Bindable] public var alphaEdit:Number = 1.0; /** * Specifies the alpha value applied to the component when it doesn't have focus and * mouse is hovering over it. * * @default 0.3 */ [Bindable] public var alphaFocus:Number = 0.3; //-------------------------------------------------------------------------- // // Methods // //-------------------------------------------------------------------------- /** * Constructor * * @param target The component on which effect must be applied. */ public function EditInPlaceEffect(target:UIComponent = null) { super(target); instanceClass = EditInPlaceEffectInstance; } /** * @private */ override protected function initInstance(instance:IEffectInstance):void { super.initInstance(instance); var valueEditInPlaceEffectInstance:EditInPlaceEffectInstance = EditInPlaceEffectInstance(instance); valueEditInPlaceEffectInstance.textProperty = textProperty; valueEditInPlaceEffectInstance.alphaRead = alphaRead; valueEditInPlaceEffectInstance.alphaFocus = alphaFocus; valueEditInPlaceEffectInstance.alphaEdit = alphaEdit; // Trick: the effect execution just registers some vent handlers for // further effects. We use the defined duration for the further effects // and update our "own" duration to asap. valueEditInPlaceEffectInstance.effectDuration = duration; valueEditInPlaceEffectInstance.duration = 1; } /** * @private */ override public function deleteInstance(instance:IEffectInstance):void { if (instance is EditInPlaceEffectInstance) EditInPlaceEffectInstance(instance).dispose(); super.deleteInstance(instance); } } }