1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2009 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 spark.effects 13{ 14import mx.core.mx_internal; 15import mx.effects.IEffectInstance; 16 17import spark.effects.animation.MotionPath; 18import spark.effects.supportClasses.AnimateTransformInstance; 19 20use namespace mx_internal; 21 22//-------------------------------------- 23// Excluded APIs 24//-------------------------------------- 25 26[Exclude(name="motionPaths", kind="property")] 27 28/** 29 * The Scale effect scales a target object 30 * in the x and y directions around the transform center. 31 * A scale of 2.0 means the object has been magnified by a factor of 2, 32 * and a scale of 0.5 means the object has been reduced by a factor of 2. 33 * A scale value of 0.0 is invalid. 34 * 35 * <p>Like all AnimateTransform-based effects, this effect will only work on subclasses 36 * of UIComponent and GraphicElement, as these effects depend on specific 37 * transform functions in those classes. </p> 38 * 39 * @mxml 40 * 41 * <p>The <code><s:Scale></code> tag 42 * inherits all of the tag attributes of its of its superclass, 43 * and adds the following tag attributes:</p> 44 * 45 * <pre> 46 * <s:Scale 47 * id="ID" 48 * scaleXBy="val" 49 * scaleXFrom="val" 50 * scaleXTo="val" 51 * scaleYBy="val" 52 * scaleYFrom="val" 53 * scaleYTo="val" 54 * /> 55 * </pre> 56 * 57 * @includeExample examples/ScaleEffectExample.mxml 58 * 59 * @langversion 3.0 60 * @playerversion Flash 10 61 * @playerversion AIR 1.5 62 * @productversion Flex 4 63 */ 64public class Scale extends AnimateTransform 65{ 66 include "../core/Version.as"; 67 68 //-------------------------------------------------------------------------- 69 // 70 // Class constants 71 // 72 //-------------------------------------------------------------------------- 73 74 /** 75 * @private 76 */ 77 private static var AFFECTED_PROPERTIES:Array = 78 ["scaleX", "scaleY", 79 "postLayoutScaleX","postLayoutScaleY", 80 "width", "height"]; 81 82 private static var RELEVANT_STYLES:Array = []; 83 84 //-------------------------------------------------------------------------- 85 // 86 // Constructor 87 // 88 //-------------------------------------------------------------------------- 89 90 /** 91 * Constructor. 92 * 93 * @param target The Object to animate with this effect. 94 * 95 * @langversion 3.0 96 * @playerversion Flash 10 97 * @playerversion AIR 1.5 98 * @productversion Flex 4 99 */ 100 public function Scale(target:Object=null) 101 { 102 super(target); 103 instanceClass = AnimateTransformInstance; 104 transformEffectSubclass = true; 105 } 106 107 //-------------------------------------------------------------------------- 108 // 109 // Properties 110 // 111 //-------------------------------------------------------------------------- 112 113 //---------------------------------- 114 // scaleYFrom 115 //---------------------------------- 116 117 [Inspectable(category="General", defaultValue="NaN")] 118 119 /** 120 * The starting scale factor in the y direction. 121 * A scale value of 0.0 is invalid. 122 * 123 * @langversion 3.0 124 * @playerversion Flash 10 125 * @playerversion AIR 1.5 126 * @productversion Flex 4 127 */ 128 public var scaleYFrom:Number; 129 130 //---------------------------------- 131 // scaleYTo 132 //---------------------------------- 133 134 [Inspectable(category="General", defaultValue="NaN")] 135 136 /** 137 * The ending scale factor in the y direction. 138 * A scale value of 0.0 is invalid. 139 * 140 * @langversion 3.0 141 * @playerversion Flash 10 142 * @playerversion AIR 1.5 143 * @productversion Flex 4 144 */ 145 public var scaleYTo:Number; 146 147 //---------------------------------- 148 // scaleYBy 149 //---------------------------------- 150 151 [Inspectable(category="General", defaultValue="NaN")] 152 153 /** 154 * The factor by which to scale the object in the y direction. 155 * This is an optional parameter that can be used instead of one 156 * of the other from/to values to specify the delta to add to the 157 * from value or to derive the from value by subtracting from the 158 * to value. 159 * 160 * @langversion 3.0 161 * @playerversion Flash 10 162 * @playerversion AIR 1.5 163 * @productversion Flex 4 164 */ 165 public var scaleYBy:Number; 166 167 //---------------------------------- 168 // scaleXFrom 169 //---------------------------------- 170 171 [Inspectable(category="General", defaultValue="NaN")] 172 173 /** 174 * The starting scale factor in the x direction. 175 * A scale value of 0.0 is invalid. 176 * 177 * @langversion 3.0 178 * @playerversion Flash 10 179 * @playerversion AIR 1.5 180 * @productversion Flex 4 181 */ 182 public var scaleXFrom:Number; 183 184 //---------------------------------- 185 // scaleXTo 186 //---------------------------------- 187 188 [Inspectable(category="General", defaultValue="NaN")] 189 190 /** 191 * The ending scale factor in the x direction. 192 * A scale value of 0.0 is invalid. 193 * 194 * @langversion 3.0 195 * @playerversion Flash 10 196 * @playerversion AIR 1.5 197 * @productversion Flex 4 198 */ 199 public var scaleXTo:Number; 200 201 //---------------------------------- 202 // scaleXBy 203 //---------------------------------- 204 205 [Inspectable(category="General", defaultValue="NaN")] 206 207 /** 208 * The factor by which to scale the object in the x direction. 209 * This is an optional parameter that can be used instead of one 210 * of the other from/to values to specify the delta to add to the 211 * from value or to derive the from value by subtracting from the 212 * to value. 213 * 214 * @langversion 3.0 215 * @playerversion Flash 10 216 * @playerversion AIR 1.5 217 * @productversion Flex 4 218 */ 219 public var scaleXBy:Number; 220 221 //-------------------------------------------------------------------------- 222 // 223 // Overridden methods 224 // 225 //-------------------------------------------------------------------------- 226 227 /** 228 * @private 229 */ 230 override public function get relevantStyles():Array /* of String */ 231 { 232 return RELEVANT_STYLES; 233 } 234 235 /** 236 * @private 237 */ 238 override public function getAffectedProperties():Array /* of String */ 239 { 240 return AFFECTED_PROPERTIES; 241 } 242 243 // TODO (chaase): Should try to remove this override. At a minimum, we could 244 // put the motionPaths creation at the start of initInstance(). Ideally, we'd 245 // remove that logic entirely, but there's a need to create motionPaths fresh 246 // for every call to create/initInstance() or else multi-instance effects 247 // will inherit the one motionPaths object created elsewhere. 248 /** 249 * @private 250 */ 251 override public function createInstance(target:Object = null):IEffectInstance 252 { 253 motionPaths = new Vector.<MotionPath>(); 254 return super.createInstance(target); 255 } 256 257 /** 258 * @private 259 */ 260 override protected function initInstance(instance:IEffectInstance):void 261 { 262 var xProp:String = applyChangesPostLayout ? "postLayoutScaleX" : "scaleX"; 263 var yProp:String = applyChangesPostLayout ? "postLayoutScaleY" : "scaleY"; 264 265 addMotionPath(xProp, scaleXFrom, scaleXTo, scaleXBy); 266 addMotionPath(yProp, scaleYFrom, scaleYTo, scaleYBy); 267 268 super.initInstance(instance); 269 } 270} 271} 272