1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2005-2007 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//////////////////////////////////////////////////////////////////////////////// 11 12package mx.effects.effectClasses 13{ 14 15import flash.events.Event; 16import mx.core.UIComponent; 17import mx.core.mx_internal; 18import mx.events.ChildExistenceChangedEvent; 19import mx.events.FlexEvent; 20import mx.geom.RoundedRectangle; 21import mx.styles.StyleManager; 22 23use namespace mx_internal; 24 25/** 26 * The DissolveInstance class implements the instance class 27 * for the Dissolve effect. 28 * Flex creates an instance of this class when it plays a Dissolve effect; 29 * you do not create one yourself. 30 * 31 * <p>Every effect class that is a subclass of the TweenEffect class 32 * supports the following events:</p> 33 * 34 * <ul> 35 * <li><code>tweenEnd</code>: Dispatched when the tween effect ends. </li> 36 * 37 * <li><code>tweenUpdate</code>: Dispatched every time a TweenEffect 38 * class calculates a new value.</li> 39 * </ul> 40 * 41 * <p>The event object passed to the event listener for these events is of type TweenEvent. 42 * The TweenEvent class defines the property <code>value</code>, which contains 43 * the tween value calculated by the effect. 44 * For the Dissolve effect, 45 * the <code>TweenEvent.value</code> property contains a Number between the values of the 46 * <code>Dissolve.alphaFrom</code> and <code>Dissolve.alphaTo</code> properties.</p> 47 * 48 * @see mx.effects.Dissolve 49 * @see mx.events.TweenEvent 50 * 51 * @langversion 3.0 52 * @playerversion Flash 9 53 * @playerversion AIR 1.1 54 * @productversion Flex 3 55 */ 56public class DissolveInstance extends TweenEffectInstance 57{ 58 include "../../core/Version.as"; 59 60 //-------------------------------------------------------------------------- 61 // 62 // Constructor 63 // 64 //-------------------------------------------------------------------------- 65 66 /** 67 * Constructor. 68 * 69 * @param target The Object to animate with this effect. 70 * 71 * @langversion 3.0 72 * @playerversion Flash 9 73 * @playerversion AIR 1.1 74 * @productversion Flex 3 75 */ 76 public function DissolveInstance(target:Object) 77 { 78 super(target); 79 } 80 81 //-------------------------------------------------------------------------- 82 // 83 // Variables 84 // 85 //-------------------------------------------------------------------------- 86 87 /** 88 * @private 89 */ 90 private var overlay:UIComponent; 91 92 //-------------------------------------------------------------------------- 93 // 94 // Properties 95 // 96 //-------------------------------------------------------------------------- 97 98 //---------------------------------- 99 // alphaFrom 100 //---------------------------------- 101 102 /** 103 * Initial transparency level between 0.0 and 1.0, 104 * where 0.0 means transparent and 1.0 means fully opaque. 105 * 106 * @langversion 3.0 107 * @playerversion Flash 9 108 * @playerversion AIR 1.1 109 * @productversion Flex 3 110 */ 111 public var alphaFrom:Number; 112 113 //---------------------------------- 114 // alphaTo 115 //---------------------------------- 116 117 /** 118 * Final transparency level between 0.0 and 1.0, 119 * where 0.0 means transparent and 1.0 means fully opaque. 120 * 121 * @langversion 3.0 122 * @playerversion Flash 9 123 * @playerversion AIR 1.1 124 * @productversion Flex 3 125 */ 126 public var alphaTo:Number; 127 128 //---------------------------------- 129 // color 130 //---------------------------------- 131 132 /** 133 * Hex value that represents the color of the floating rectangle 134 * that the effect displays over the target object. 135 * 136 * The default value is the color specified by the target component's 137 * <code>backgroundColor</code> style property, or 0xFFFFFF, if 138 * <code>backgroundColor</code> is not set. 139 * 140 * @langversion 3.0 141 * @playerversion Flash 9 142 * @playerversion AIR 1.1 143 * @productversion Flex 3 144 */ 145 public var color:uint = StyleManager.NOT_A_COLOR; 146 147 //---------------------------------- 148 // persistAfterEnd 149 //---------------------------------- 150 151 /** 152 * @private 153 */ 154 mx_internal var persistAfterEnd:Boolean = false; 155 156 //---------------------------------- 157 // targetArea 158 //---------------------------------- 159 160 /** 161 * The area of the target to play the effect upon. 162 * The dissolve overlay is drawn using this property's dimensions. 163 * UIComponents create an overlay over the entire component. 164 * Containers create an overlay over their content area, 165 * but not their chrome. 166 * 167 * @langversion 3.0 168 * @playerversion Flash 9 169 * @playerversion AIR 1.1 170 * @productversion Flex 3 171 */ 172 public var targetArea:RoundedRectangle; 173 174 //-------------------------------------------------------------------------- 175 // 176 // Overridden methods 177 // 178 //-------------------------------------------------------------------------- 179 180 /** 181 * @private 182 */ 183 override public function initEffect(event:Event):void 184 { 185 super.initEffect(event); 186 187 switch (event.type) 188 { 189 case "childrenCreationComplete": 190 case FlexEvent.CREATION_COMPLETE: 191 case "resizeEnd": 192 case FlexEvent.SHOW: 193 case Event.ADDED: 194 { 195 if (isNaN(alphaFrom)) 196 alphaFrom = 0; 197 if (isNaN(alphaTo)) 198 alphaTo = target.alpha; 199 break; 200 } 201 202 case FlexEvent.HIDE: 203 case "resizeStart": 204 case Event.REMOVED: 205 { 206 if (isNaN(alphaFrom)) 207 alphaFrom = target.alpha; 208 if (isNaN(alphaTo)) 209 alphaTo = 0; 210 break; 211 } 212 } 213 } 214 215 /** 216 * @private 217 */ 218 override public function play():void 219 { 220 super.play(); 221 222 var values:PropertyChanges = propertyChanges; 223 224 // If nobody assigned a value, make this a "show" effect. 225 if (isNaN(alphaFrom) && isNaN(alphaTo)) 226 { 227 // If we are in transition mode 228 if (values && values.end["alpha"] !== undefined) 229 { 230 alphaFrom = target.alpha; 231 alphaTo = values.end["alpha"]; 232 } 233 else if (values && values.end["visible"] !== undefined) 234 { 235 alphaFrom = values.start["visible"] ? target.alpha : 0; 236 alphaTo = values.end["visible"] ? target.alpha : 0; 237 } 238 else 239 { 240 alphaFrom = 0; 241 alphaTo = target.alpha; 242 } 243 } 244 else if (isNaN(alphaFrom)) 245 { 246 alphaFrom = (alphaTo == 0) ? target.alpha : 0; 247 } 248 else if (isNaN(alphaTo)) 249 { 250 if (values && values.end["alpha"] !== undefined) 251 alphaTo = values.end["alpha"]; 252 else 253 alphaTo = (alphaFrom == 0) ? target.alpha : 0; 254 } 255 256 // If nobody assigned a color, then use the target's background color. 257 if (color == StyleManager.NOT_A_COLOR) 258 { 259 color = 0xFFFFFF; 260 var bgColor:Number = target.getStyle("backgroundColor"); 261 if (isNaN(bgColor) && target.parent) 262 { 263 bgColor = target.parent.getStyle("backgroundColor"); 264 } 265 if (!isNaN(bgColor)) 266 { 267 color = uint(bgColor); 268 } 269 } 270 271 // Capture the target's width and height before creating the overlay. 272 // Label is a subclass of UIComponent, so creating an overlay 273 // for the label will change the label's width and height. 274 var targetWidth:Number = target.width; 275 var targetHeight:Number = target.height; 276 277 target.addEventListener(ChildExistenceChangedEvent.OVERLAY_CREATED, 278 overlayCreatedHandler); 279 280 target.addOverlay(color, targetArea); 281 //overlay.cacheAsBitmap = true; 282 } 283 284 /** 285 * @private 286 */ 287 override public function onTweenUpdate(value:Object):void 288 { 289 overlay.alpha = Number(value); 290 } 291 292 /** 293 * @private 294 */ 295 override public function onTweenEnd(value:Object):void 296 { 297 super.onTweenEnd(value); 298 299 if (!persistAfterEnd) 300 target.removeOverlay(); 301 } 302 303 //-------------------------------------------------------------------------- 304 // 305 // Event handlers 306 // 307 //-------------------------------------------------------------------------- 308 309 /** 310 * @private 311 */ 312 private function overlayCreatedHandler(event:ChildExistenceChangedEvent):void 313 { 314 target.removeEventListener(ChildExistenceChangedEvent.OVERLAY_CREATED, 315 overlayCreatedHandler); 316 317 event.stopImmediatePropagation(); 318 319 overlay = UIComponent(event.relatedObject); 320 321 // Create a tween. 322 tween = createTween(this, 1.0 - alphaFrom, 323 1.0 - alphaTo, duration); 324 325 // Set the animation to the initial value before the screen refreshes. 326 applyTweenStartValues(); 327 } 328 329} 330} 331