Package | com.greensock.transform |
Class | public class TransformManager |
Inheritance | TransformManager flash.events.EventDispatcher |
FEATURES INCLUDE:
FlexTransformManager
class that makes it simple to integrate into Flex applications.NOTES / LIMITATIONS:
USAGE
The first (and only) parameter in the constructor should be an object with any number of properties. This makes it easier to set only the properties that shouldn't use their default values (you'll probably find that most of the time the default values work well for you). It also makes the code easier to read. The properties can be in any order, like so:
var manager:TransformManager = new TransformManager({targetObjects:[mc1, mc2], forceSelectionToFront:true, bounds:new Rectangle(0, 0, 550, 450), allowDelete:true});
All TransformEvents have an "items" property which is an Array populated by the affected TransformItem instances. TransformEvents also have a "mouseEvent" property that will be populated if there was an associted MouseEvent (like CLICK_OFF)
EXAMPLES:
To make two MovieClips (mc1 and mc2) transformable using the default settings:
import com.greensock.transform.TransformManager; var manager:TransformManager = new TransformManager({targetObjects:[mc1, mc2]});
To make the two MovieClips transformable, constrain their scaling to be proportional (even if the user is not holding down the shift key), call the onScale function everytime one of the objects is scaled, lock the rotation value of each MovieClip (preventing rotation), and allow the delete key to appear to delete the selected MovieClip from the stage:
import com.greensock.transform.TransformManager; import com.greensock.events.TransformEvent; var manager:TransformManager = new TransformManager({targetObjects:[mc1, mc2], constrainScale:true, lockRotation:true, allowDelete:true, autoDeselect:true}); manager.addEventListener(TransformEvent.SCALE, onScale); function onScale(event:TransformEvent):void { trace("Scaled " + event.items.length + " items"); }
To add mc1 and mc2 and myText after a TransformManager has been created, and then listen for when only mc1 is selected:
import com.greensock.transform.TransformManager; import com.greensock.transform.TransformItem; import com.greensock.events.TransformEvent; var manager:TransformManager = new TransformManager(); var mc1Item:TransformItem = manager.addItem(mc1); var mc2Item:TransformItem = manager.addItem(mc2); var myTextItem:TransformItem = manager.addItem(myText, TransformManager.SCALE_WIDTH_AND_HEIGHT, true); mc1Item.addEventListener(TransformEvent.SELECT, onSelectClip1); function onSelectClip1(event:TransformEvent):void { trace("selected mc1"); }
A note about using fl.controls.* Flash components like TextArea and TextInput: Due to the fact that these components have certain inconsistencies and quirks, by default they will act slightly strange with TransformManager (selection box will appear off by about 2 pixels in each direction and the text will scale). However, it is relatively easy to work around these issues by changing their style's "focusRectPadding" and adding a RENDER event listener that calls drawFocus(false) on your TextArea/TextInput instance like this:
//add a TextArea instance ("textArea") to the TransformManager instance ("manager") var item:TransformItem = manager.addItem(textArea); //set hasSelectableText to true so that its width/height are altered rather than scaleX/scaleY and the custom cursors don't interfere when hovering item.hasSelectableText = true; //focusRectPadding must be 0 to eliminate the offset textArea.setStyle("focusRectPadding", 0); //listen for the textArea's RENDER event and call drawFocus() in order to work around a problem with the components that can leave an odd focus rectangle in place after scaling textArea.addEventListener(Event.RENDER, fixFocusRect); function fixFocusRect(event:Event):void { event.target.drawFocus(false); }
TransformManager attempts to automatically determine whether or not it is being used inside of
a Flex app (which means it must use UIComponents and make a few other accommodations), but if you want to force
TransformManager into Flex mode (or not), simply define the flexMode
special property in the vars
object like var manager:TransformManager = new TransformManager({flexMode:false});
(added in version 1.955)
Copyright 2007-2012, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/eula.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
Property | Defined By | ||
---|---|---|---|
allowDelete : Boolean If true, when the user presses the DELETE (or BACKSPACE) key, the selected item(s) will be deleted (except items with hasSelectableText set to true) [default: false] | TransformManager | ||
allowMultiSelect : Boolean If true, multiple items can be selected by holding down the SHIFT or CONTROL keys and clicking [default: true]. | TransformManager | ||
arrowKeysMove : Boolean If true, the arrow keys on the keyboard will move the selected items when pressed [default: false] | TransformManager | ||
autoDeselect : Boolean When the user clicks anywhere OTHER than on one of the TransformItems, all are deselected [default: true] | TransformManager | ||
bounds : Rectangle A Rectangle defining the boundaries for movement/scaling/rotation. | TransformManager | ||
constrainScale : Boolean To constrain items to only scaling proportionally, set this to true [default: false] | TransformManager | ||
enabled : Boolean Enable or disable the entire TransformManager. | TransformManager | ||
forceSelectionToFront : Boolean When true, new selections are forced to the front (top) of the display list [default: true] | TransformManager | ||
handleFillColor : uint Controls the fill color of the handle [default: 0xFFFFFF] | TransformManager | ||
handleSize : Number Controls the handle size (in pixels) [default: 8] | TransformManager | ||
hideCenterHandle : Boolean To hide the center scale handle, set this to true [default: false] | TransformManager | ||
ignoredObjects : Array If you want TransformManager to ignore clicks on certain DisplayObjects like buttons, color pickers, etc., add them to the ignoredObjects Array. | TransformManager | ||
isShowingCustomCursor : Boolean [read-only] If true, TransformManager is currently displaying a custom cursor (like the scale, rotate, or move cursor). | TransformManager | ||
items : Array [read-only] All of the TransformItem instances that are managed by this TransformManager (regardless of whether or not they're selected) | TransformManager | ||
lineColor : uint Controls the line color of the selection box and handles [default: 0x3399FF] | TransformManager | ||
lineThickness : Number Controls the thickness of the selection box and handle lines [default: 1] | TransformManager | ||
lockPosition : Boolean Prevents moving [default: false] | TransformManager | ||
lockRotation : Boolean Prevents rotating [default: false] | TransformManager | ||
lockScale : Boolean Prevents scaling [default: false] | TransformManager | ||
moveCursor : Shape [static] [read-only] The Shape object that is being used for the move cursor. | TransformManager | ||
paddingForRotation : Number Determines the amount of space outside each of the four corner scale handles that will trigger rotation mode [default: 12] | TransformManager | ||
rotationCursor : Shape [static] [read-only] The Shape object that is being used for the rotation cursor. | TransformManager | ||
scaleCursor : Shape [static] [read-only] The Shape object that is being used for the scale cursor. | TransformManager | ||
scaleFromCenter : Boolean If true, scaling occurs from the center of the selection instead of the corners. | TransformManager | ||
selectedItems : Array The currently selected TransformItems (for the associated DisplayObjects, use selectedTargetObjects) | TransformManager | ||
selectedTargetObjects : Array The currently selected targetObjects (DisplayObjects). | TransformManager | ||
selectionRotation : Number The rotation of the overall selection box | TransformManager | ||
selectionScaleX : Number The scaleX of the overall selection box | TransformManager | ||
selectionScaleY : Number The scaleY of the overall selection box | TransformManager | ||
selectionX : Number The x-coordinte of the overall selection box (same as the origin) | TransformManager | ||
selectionY : Number The y-coordinate of the overall selection box (same as the origin) | TransformManager | ||
targetObjects : Array [read-only] All of the targetObjects (DisplayObjects) that are managed by this TransformManager (regardless of whether or not they're selected) | TransformManager |
Method | Defined By | ||
---|---|---|---|
TransformManager($vars:Object = null)
Constructor
| TransformManager | ||
addEventListener($type:String, $listener:Function, $useCapture:Boolean = false, $priority:int = 0, $useWeakReference:Boolean = false):void [override]
Allows listening for the following events:
TransformEvent.MOVE
TransformEvent.SCALE
TransformEvent.ROTATE
TransformEvent.DELETE
TransformEvent.SELECTION_CHANGE
TransformEvent.CLICK_OFF
TransformEvent.SEIZE_CURSOR
TransformEvent.RELEASE_CURSOR
TransformEvent.DEPTH_CHANGE
TransformEvent.DESTROY
TransformEvent.START_INTERACTIVE_MOVE
TransformEvent.START_INTERACTIVE_SCALE
TransformEvent.START_INTERACTIVE_ROTATE
TransformEvent.FINISH_INTERACTIVE_MOVE
TransformEvent.FINISH_INTERACTIVE_SCALE
TransformEvent.FINISH_INTERACTIVE_ROTATE
TransformEvent.DOUBLE_CLICK
| TransformManager | ||
addIgnoredObject($object:DisplayObject):void
Allows you to have TransformManager ignore clicks on a particular DisplayObject (handy for buttons, color pickers, etc.). | TransformManager | ||
addItem($targetObject:DisplayObject, $scaleMode:String = scaleNormal, $hasSelectableText:Boolean = false):TransformItem
In order for a DisplayObject to be managed by TransformManger, it must first be added via addItem(). | TransformManager | ||
addItems($targetObjects:Array, $scaleMode:String = scaleNormal, $hasSelectableText:Boolean = false):Array
Same as addItem() but accepts an Array containing multiple DisplayObjects. | TransformManager | ||
addSelectionBoxElement(element:DisplayObject, alignment:String = topRight, xOffset:Number = 0, yOffset:Number = 0, underHandles:Boolean = false):void
Attaches a DisplayObject of your choice to the selection box itself so that it appears to move
with the selection box as the user interacts with it. | TransformManager | ||
applyFullXML(xml:XML, defaultParent:DisplayObjectContainer, placeholderColor:uint = 0xCCCCCC):Array
Applies XML generated by exportFullXML() to the TransformManager instance including all settings
and each item's scale/rotation/position. | TransformManager | ||
applyItemXML(xml:XML, defaultParent:DisplayObjectContainer = null, placeholderColor:uint = 0xCCCCCC):DisplayObject
Applies XML generated by exportItemXML() to the TransformManager instance including all transform
data like scale/rotation/position. | TransformManager | ||
applySettingsXML(xml:XML):void
Applies settings XML generated by exportSettingsXML() to the TransformManager instance. | TransformManager | ||
customizeMoveCursor(cursor:Shape = null, hideMouse:Boolean = true, xOffset:Number = 0, yOffset:Number = 0):void [static]
Facilitates the customization of the move cursor so that you can optionally define a Shape object
to use as a cursor (if null, TransformManager will use its default move cursor), and also optionally
hide the Mouse when the cursor is used and/or define x and y offset values (measured from the
Mouse position). | TransformManager | ||
customizeRotationCursor(cursor:Shape = null, hideMouse:Boolean = true, xOffset:Number = 0, yOffset:Number = 0, autoRotate:Boolean = true):void [static]
Facilitates the customization of the rotation cursor so that you can optionally define a Shape object
to use as a cursor (if null, TransformManager will use its default rotation cursor), and also optionally
hide the Mouse when the cursor is used and/or define x and y offset values (measured from the
Mouse position). | TransformManager | ||
customizeScaleCursor(cursor:Shape = null, hideMouse:Boolean = true, xOffset:Number = 0, yOffset:Number = 0, autoRotate:Boolean = true):void [static]
Facilitates the customization of the scale cursor so that you can optionally define a Shape object
to use as a cursor (if null, TransformManager will use its default scale cursor), and also optionally
hide the Mouse when the cursor is used and/or define x and y offset values (measured from the
Mouse position). | TransformManager | ||
deleteSelection($e:Event = null):void
Deletes all selected items. | TransformManager | ||
deselectAll():void Deselects all items | TransformManager | ||
deselectItem($item:*):TransformItem
Deselects a TransformItem or DisplayObject. | TransformManager | ||
destroy():void Destroys the TransformManager instance, removing all items and preparing it for garbage collection | TransformManager | ||
exportFullXML():XML
A common request is to capture the current state of each item's scale/rotation/position and the TransformManager's
settings in an easy-to-store format so that the data can be reloaded and applied later; exportFullXML()
returns an XML object containing exactly that. | TransformManager | ||
exportItemXML(targetObject:DisplayObject):XML
Exports transform data (scale/rotation/position) of a particular DisplayObject in XML format so that
it can be saved to a database or elsewhere easily and then reapplied later. | TransformManager | ||
exportSettingsXML():XML
Exports the TransformManager's settings in XML format so that it can be saved to a database or elsewhere easily
and then reapplied later. | TransformManager | ||
flipSelectionHorizontal():void Flips the selected items horizontally | TransformManager | ||
flipSelectionVertical():void Flips the selected items vertically | TransformManager | ||
getItem($targetObject:DisplayObject):TransformItem
Gets the TransformItem associated with a particular DisplayObject (if any). | TransformManager | ||
getSelectionBounds(targetCoordinateSpace:DisplayObject = null):Rectangle
Gets the bounding Rectangle of the current selection (not including handles)
| TransformManager | ||
getSelectionBoundsWithHandles(targetCoordinateSpace:DisplayObject = null):Rectangle
Gets the bounding Rectangle of the current selection (including handles)
| TransformManager | ||
getSelectionCenter():Point
Gets the center point of the current selection
| TransformManager | ||
getUnrotatedSelectionHeight():Number
Gets the height of the selection as if it were not rotated. | TransformManager | ||
getUnrotatedSelectionWidth():Number
Gets the width of the selection as if it were not rotated. | TransformManager | ||
isSelected($item:*):Boolean
Determines whether or not a particular DisplayObject or TranformItem is currently selected. | TransformManager | ||
moveSelection($x:Number, $y:Number, $dispatchEvents:Boolean = true):void
Moves the selected items by a certain number of pixels on the x axis and y axis
| TransformManager | ||
moveSelectionDepthDown():void Moves the selection down one level. | TransformManager | ||
moveSelectionDepthUp():void Moves the selection up one level. | TransformManager | ||
removeAllItems():void Removes all items from the TransformManager instance. | TransformManager | ||
removeIgnoredObject($object:DisplayObject):void
Removes an ignored DisplayObject so that its clicks are no longer ignored. | TransformManager | ||
removeItem($item:*):void
Removes an item. | TransformManager | ||
removeSelectionBoxElement(element:DisplayObject):void
Releases a DisplayObject that was attached using addSelectionBoxElement(). | TransformManager | ||
rotateSelection($angle:Number, $dispatchEvents:Boolean = true):void
Rotates the selected items by a particular angle (in Radians). | TransformManager | ||
scaleSelection($sx:Number, $sy:Number, $dispatchEvents:Boolean = true):void
Scales the selected items along the x- and y-axis using multipliers. | TransformManager | ||
selectItem($item:*, $addToSelection:Boolean = false):TransformItem
Selects a particular TransformItem or DisplayObject (you must have already added the DisplayObject
to TransformManager in order for it to be selectable - use addItem() for that)
| TransformManager | ||
selectItems($items:Array, $addToSelection:Boolean = false):Array
Selects an Array of TransformItems and/or DisplayObjects. | TransformManager | ||
updateSelection($centerOrigin:Boolean = true):void
Refreshes the selection box/handles. | TransformManager |
Constant | Defined By | ||
---|---|---|---|
SCALE_NORMAL : String = scaleNormal [static] Normal scale mode | TransformManager | ||
SCALE_WIDTH_AND_HEIGHT : String = scaleWidthAndHeight [static] Scale only width and height properties | TransformManager |
allowDelete | property |
allowDelete:Boolean
If true, when the user presses the DELETE (or BACKSPACE) key, the selected item(s) will be deleted (except items with hasSelectableText
set to true) [default: false
]
public function get allowDelete():Boolean
public function set allowDelete(value:Boolean):void
allowMultiSelect | property |
allowMultiSelect:Boolean
If true, multiple items can be selected by holding down the SHIFT or CONTROL keys and clicking [default: true
]. Just like in most modern operating systems, SHIFT always adds to the selection while CTRL toggles items in the selection.
public function get allowMultiSelect():Boolean
public function set allowMultiSelect(value:Boolean):void
arrowKeysMove | property |
arrowKeysMove:Boolean
If true, the arrow keys on the keyboard will move the selected items when pressed [default: false
]
public function get arrowKeysMove():Boolean
public function set arrowKeysMove(value:Boolean):void
autoDeselect | property |
autoDeselect:Boolean
When the user clicks anywhere OTHER than on one of the TransformItems, all are deselected [default: true
]
public function get autoDeselect():Boolean
public function set autoDeselect(value:Boolean):void
bounds | property |
bounds:Rectangle
A Rectangle defining the boundaries for movement/scaling/rotation. [default:null]
public function get bounds():Rectangle
public function set bounds(value:Rectangle):void
constrainScale | property |
constrainScale:Boolean
To constrain items to only scaling proportionally, set this to true [default: false
]
public function get constrainScale():Boolean
public function set constrainScale(value:Boolean):void
enabled | property |
enabled:Boolean
Enable or disable the entire TransformManager.
public function get enabled():Boolean
public function set enabled(value:Boolean):void
forceSelectionToFront | property |
forceSelectionToFront:Boolean
When true, new selections are forced to the front (top) of the display list [default: true
]
public function get forceSelectionToFront():Boolean
public function set forceSelectionToFront(value:Boolean):void
handleFillColor | property |
handleFillColor:uint
Controls the fill color of the handle [default: 0xFFFFFF
]
public function get handleFillColor():uint
public function set handleFillColor(value:uint):void
handleSize | property |
handleSize:Number
Controls the handle size (in pixels) [default: 8
]
public function get handleSize():Number
public function set handleSize(value:Number):void
hideCenterHandle | property |
hideCenterHandle:Boolean
To hide the center scale handle, set this to true [default: false
]
public function get hideCenterHandle():Boolean
public function set hideCenterHandle(value:Boolean):void
ignoredObjects | property |
ignoredObjects:Array
If you want TransformManager to ignore clicks on certain DisplayObjects like buttons, color pickers, etc., add them to the ignoredObjects Array. The DisplayObject CANNOT be a child of a targetObject that is being managed by TransformManager.
public function get ignoredObjects():Array
public function set ignoredObjects(value:Array):void
isShowingCustomCursor | property |
isShowingCustomCursor:Boolean
[read-only] If true
, TransformManager is currently displaying a custom cursor (like the scale, rotate, or move cursor).
public function get isShowingCustomCursor():Boolean
items | property |
items:Array
[read-only] All of the TransformItem instances that are managed by this TransformManager (regardless of whether or not they're selected)
public function get items():Array
lineColor | property |
lineColor:uint
Controls the line color of the selection box and handles [default: 0x3399FF
]
public function get lineColor():uint
public function set lineColor(value:uint):void
lineThickness | property |
lineThickness:Number
Controls the thickness of the selection box and handle lines [default: 1
]
public function get lineThickness():Number
public function set lineThickness(value:Number):void
lockPosition | property |
lockPosition:Boolean
Prevents moving [default: false
]
public function get lockPosition():Boolean
public function set lockPosition(value:Boolean):void
lockRotation | property |
lockRotation:Boolean
Prevents rotating [default: false
]
public function get lockRotation():Boolean
public function set lockRotation(value:Boolean):void
lockScale | property |
lockScale:Boolean
Prevents scaling [default: false
]
public function get lockScale():Boolean
public function set lockScale(value:Boolean):void
moveCursor | property |
moveCursor:Shape
[read-only] The Shape object that is being used for the move cursor. To customize the cursor, use the customizeMoveCursor()
method.
public static function get moveCursor():Shape
See also
paddingForRotation | property |
paddingForRotation:Number
Determines the amount of space outside each of the four corner scale handles that will trigger rotation mode [default: 12
]
public function get paddingForRotation():Number
public function set paddingForRotation(value:Number):void
rotationCursor | property |
rotationCursor:Shape
[read-only] The Shape object that is being used for the rotation cursor. To customize the cursor, use the customizeRotationCursor()
method.
public static function get rotationCursor():Shape
See also
scaleCursor | property |
scaleCursor:Shape
[read-only] The Shape object that is being used for the scale cursor. To customize the cursor, use the customizeScaleCursor()
method.
public static function get scaleCursor():Shape
See also
scaleFromCenter | property |
scaleFromCenter:Boolean
If true, scaling occurs from the center of the selection instead of the corners. [default: false
]
public function get scaleFromCenter():Boolean
public function set scaleFromCenter(value:Boolean):void
selectedItems | property |
selectedItems:Array
The currently selected TransformItems (for the associated DisplayObjects, use selectedTargetObjects
)
public function get selectedItems():Array
public function set selectedItems(value:Array):void
selectedTargetObjects | property |
selectedTargetObjects:Array
The currently selected targetObjects (DisplayObjects). For the associated TransformItems, use selectedItems
.
public function get selectedTargetObjects():Array
public function set selectedTargetObjects(value:Array):void
selectionRotation | property |
selectionRotation:Number
The rotation of the overall selection box
public function get selectionRotation():Number
public function set selectionRotation(value:Number):void
selectionScaleX | property |
selectionScaleX:Number
The scaleX of the overall selection box
public function get selectionScaleX():Number
public function set selectionScaleX(value:Number):void
selectionScaleY | property |
selectionScaleY:Number
The scaleY of the overall selection box
public function get selectionScaleY():Number
public function set selectionScaleY(value:Number):void
selectionX | property |
selectionX:Number
The x-coordinte of the overall selection box (same as the origin)
public function get selectionX():Number
public function set selectionX(value:Number):void
selectionY | property |
selectionY:Number
The y-coordinate of the overall selection box (same as the origin)
public function get selectionY():Number
public function set selectionY(value:Number):void
targetObjects | property |
targetObjects:Array
[read-only] All of the targetObjects (DisplayObjects) that are managed by this TransformManager (regardless of whether or not they're selected)
public function get targetObjects():Array
TransformManager | () | Constructor |
public function TransformManager($vars:Object = null)
Constructor
Parameters$vars:Object (default = null ) — An object specifying any properties that should be set upon instantiation, like {items:[mc1, mc2], lockRotation:true, bounds:new Rectangle(0, 0, 500, 300)} .
|
addEventListener | () | method |
override public function addEventListener($type:String, $listener:Function, $useCapture:Boolean = false, $priority:int = 0, $useWeakReference:Boolean = false):void
Allows listening for the following events:
Parameters
$type:String — Event type
| |
$listener:Function — Listener function
| |
$useCapture:Boolean (default = false ) — Use capture phase
| |
$priority:int (default = 0 ) — Priority
| |
$useWeakReference:Boolean (default = false ) — Use weak reference
|
addIgnoredObject | () | method |
public function addIgnoredObject($object:DisplayObject):void
Allows you to have TransformManager ignore clicks on a particular DisplayObject (handy for buttons, color pickers, etc.). The DisplayObject CANNOT be a child of a targetObject
Parameters
$object:DisplayObject — DisplayObject that should be ignored
|
addItem | () | method |
public function addItem($targetObject:DisplayObject, $scaleMode:String = scaleNormal, $hasSelectableText:Boolean = false):TransformItem
In order for a DisplayObject to be managed by TransformManger, it must first be added via addItem()
. When the
DisplayObject is added, a TransformItem instance is automatically created and associated with the DisplayObject.
If you need to set item-specific settings like minScaleX, maxScaleX, etc., you would set those via the TransformItem
instance. addItem()
returns a TransformItem instance, but you can retrieve it anytime with the getItem()
method (just pass it your DisplayObject, like var myItem:TransformItem = myManager.getItem(myDisplayObject)
NOTE: If your targetObject isn't an InteractiveObject, it will not receive MouseEvents like clicks and rollovers that trigger selection, dragging, cursor changes, etc. so user interaction-based actions won't be possible. That may be perfectly acceptable, though, if you're going to do transformations directly via code.
Parameters
$targetObject:DisplayObject — The DisplayObject to be managed
| |
$scaleMode:String (default = scaleNormal ) — Either TransformManager.SCALE_NORMAL for normal scaleX/scaleY scaling or TransformManager.SCALE_WIDTH_AND_HEIGHT if you prefer that TransformManager alters the width /height properties instead.
| |
$hasSelectableText:Boolean (default = false ) — If true, this prevents dragging of the object unless clicking on the edges/border or center handle, and allows the DELETE key to be pressed without deleting the object itself. It will also force the scaleMode to TransformManager.SCALE_WIDTH_AND_HEIGHT .
|
TransformItem — TransformItem instance
|
addItems | () | method |
public function addItems($targetObjects:Array, $scaleMode:String = scaleNormal, $hasSelectableText:Boolean = false):Array
Same as addItem() but accepts an Array containing multiple DisplayObjects.
Parameters
$targetObjects:Array — An Array of DisplayObject to be managed
| |
$scaleMode:String (default = scaleNormal ) — Either TransformManager.SCALE_NORMAL for normal scaleX/scaleY scaling or TransformManager.SCALE_WIDTH_AND_HEIGHT if you prefer that TransformManager alters the width /height properties instead.
| |
$hasSelectableText:Boolean (default = false ) — If true, this prevents dragging of the objects unless clicking on the edges/border or center handle, and allows the DELETE key to be pressed without deleting the object itself. It will also force the scaleMode to TransformManager.SCALE_WIDTH_AND_HEIGHT .
|
Array — An Array of corresponding TransformItems that are created
|
addSelectionBoxElement | () | method |
public function addSelectionBoxElement(element:DisplayObject, alignment:String = topRight, xOffset:Number = 0, yOffset:Number = 0, underHandles:Boolean = false):void
Attaches a DisplayObject of your choice to the selection box itself so that it appears to move with the selection box as the user interacts with it. This is a great way to add your own interface elements, like a "delete" icon/button. You can set the alignment to any of the selection handles: "topLeft", "top", "topRight", "right", "bottomRight", "bottom", "bottomLeft", "center" or "left" and you can also define offset values so that the object doesn't sit right on top of the handle (or just alter the registration point of your DisplayObject to accomplish something similar). For example, if I want to attach a Sprite named "deleteButton" to the selection box in the upper right corner and offset it by 40 pixels on the x-axis and 0 pixels on the y-axis, I'd do:
myManager.addSelectionBoxElement(deleteButton, "topRight", 40, 0);
Parameters
element:DisplayObject — The DisplayObject to attach to the selection (it will be moved into the selection Sprite that TransformManager uses)
| |
alignment:String (default = topRight ) — "topLeft", "top", "topRight", "right", "bottomRight", "bottom", "bottomLeft", "center" or "left"
| |
xOffset:Number (default = 0 ) — The number of pixels to offset the element on the x-axis (when the selection box isn't rotated)
| |
yOffset:Number (default = 0 ) — The number of pixels to offset the element on the y-axis (when the selection box isn't rotated)
| |
underHandles:Boolean (default = false ) — By default, the element will be placed above the scale/rotation handles, but if you prefer that the element is positioned under the handles, set underHandles to true
|
See also
applyFullXML | () | method |
public function applyFullXML(xml:XML, defaultParent:DisplayObjectContainer, placeholderColor:uint = 0xCCCCCC):Array
Applies XML generated by exportFullXML()
to the TransformManager instance including all settings
and each item's scale/rotation/position. This does not load any external images/assets - you must do that separately.
Typically it's best to fully load the assets first and add them to the display list before calling applyFullXML()
.
When applyFullXML()
is called, it attempts to find the targetObjects in the display list based on their names,
but for each one that cannot be found, a new Sprite will be created and added as a placeholder, filled with the
placeholderColor
and named identically. An array of those placeholders (if any) is returned by
applyFullXML()
which makes it easy to loop through and load your images/assets directly into those
placeholder Sprites. Feel free to add visual preloaders, alter the look of the Sprites, etc.
Parameters
xml:XML — An XML object containing data about the settings and each item's position/scale/rotation. This XML is typically created using exportFullXML() .
| |
defaultParent:DisplayObjectContainer — If no items have been added to the TransformManager yet, it won't know which DisplayObjectContainer to look in for targetObjects, so it is important to explicitly tell TransformManager what default parent to use.
| |
placeholderColor:uint (default = 0xCCCCCC ) — If an item's targetObject cannot be found in the display list (based on its name), it will create a new Sprite and fill it with this color, using it as a placeholder.
|
Array — An array of placeholders that were created for missing targetObjects (if any). You can loop through these and load your assets accordingly. Keep in mind that the placeholders will have the same name as was defined in the XML (from the original targetObject).
|
See also
applyItemXML | () | method |
public function applyItemXML(xml:XML, defaultParent:DisplayObjectContainer = null, placeholderColor:uint = 0xCCCCCC):DisplayObject
Applies XML generated by exportItemXML()
to the TransformManager instance including all transform
data like scale/rotation/position. This does not load any external images/assets - you must do that separately.
Typically it's best to fully load the asset first and add them to the display list before calling applyItemXML()
.
When applyItemXML()
is called, it attempts to find the targetObject in the display list based on
its name, but if it cannot be found, a new Sprite will be created and added as a placeholder, filled with the
placeholderColor
and named identically. To load all of the settings and every item's transform
data, use applyFullXML()
instead.
Parameters
xml:XML — An XML object containing data about the item's position/scale/rotation. This XML is typically created using exportItemXML() .
| |
defaultParent:DisplayObjectContainer (default = null ) — If no items have been added to the TransformManager yet, it won't know which DisplayObjectContainer to look in for targetObject, so it is important to explicitly tell TransformManager what default parent to use.
| |
placeholderColor:uint (default = 0xCCCCCC ) — If the targetObject cannot be found in the display list (based on its name), it will create a new Sprite and fill it with this color, using it as a placeholder.
|
DisplayObject — The DisplayObject associated with the item (a placeholder Sprite if the targeObject wasn't found in the display list).
|
See also
applySettingsXML | () | method |
public function applySettingsXML(xml:XML):void
Applies settings XML generated by exportSettingsXML()
to the TransformManager instance.
This determines things like allowDelete, autoDeselect, lockScale, lockPosition,
etc.
Parameters
xml:XML — An XML object containing settings data about the TransformManager (typically exported by exportSettingsXML() ).
|
See also
customizeMoveCursor | () | method |
public static function customizeMoveCursor(cursor:Shape = null, hideMouse:Boolean = true, xOffset:Number = 0, yOffset:Number = 0):void
Facilitates the customization of the move cursor so that you can optionally define a Shape object to use as a cursor (if null, TransformManager will use its default move cursor), and also optionally hide the Mouse when the cursor is used and/or define x and y offset values (measured from the Mouse position). For example, to use the default move cursor but have it act as a decorator for the Mouse instead of replacing it, you could do this:
TransformManager.customizeMoveCursor(null, false, 20, 24);
Parameters
cursor:Shape (default = null ) — The custom Shape object that should be used for the cursor. If null , TransformManager will use its default move cursor Shape.
| |
hideMouse:Boolean (default = true ) — If true , the Mouse cursor will be hidden when the custom cursor is used.
| |
xOffset:Number (default = 0 ) — The number of pixels to offset the custom cursor horizontally, measured from the Mouse position.
| |
yOffset:Number (default = 0 ) — The number of pixels to offset the custom cursor vertically, measured from the Mouse position.
|
customizeRotationCursor | () | method |
public static function customizeRotationCursor(cursor:Shape = null, hideMouse:Boolean = true, xOffset:Number = 0, yOffset:Number = 0, autoRotate:Boolean = true):void
Facilitates the customization of the rotation cursor so that you can optionally define a Shape object to use as a cursor (if null, TransformManager will use its default rotation cursor), and also optionally hide the Mouse when the cursor is used and/or define x and y offset values (measured from the Mouse position). For example, to use the default rotation cursor but have it act as a decorator for the Mouse instead of replacing it, you could do this:
TransformManager.customizeRotationCursor(null, false, 15, 21, false);
Parameters
cursor:Shape (default = null ) — The custom Shape object that should be used for the cursor. If null , TransformManager will use its default rotation cursor Shape.
| |
hideMouse:Boolean (default = true ) — If true , the Mouse cursor will be hidden when the custom cursor is used.
| |
xOffset:Number (default = 0 ) — The number of pixels to offset the custom cursor horizontally, measured from the Mouse position.
| |
yOffset:Number (default = 0 ) — The number of pixels to offset the custom cursor vertically, measured from the Mouse position.
| |
autoRotate:Boolean (default = true ) — To automatically rotate the cursor based on its position on the selection, set autoRotate to true .
|
customizeScaleCursor | () | method |
public static function customizeScaleCursor(cursor:Shape = null, hideMouse:Boolean = true, xOffset:Number = 0, yOffset:Number = 0, autoRotate:Boolean = true):void
Facilitates the customization of the scale cursor so that you can optionally define a Shape object to use as a cursor (if null, TransformManager will use its default scale cursor), and also optionally hide the Mouse when the cursor is used and/or define x and y offset values (measured from the Mouse position). For example, to use the default scale cursor but have it act as a decorator for the Mouse instead of replacing it, you could do this:
TransformManager.customizeScaleCursor(null, false, 16, 26, false);
Parameters
cursor:Shape (default = null ) — The custom Shape object that should be used for the cursor. If null , TransformManager will use its default scale cursor Shape.
| |
hideMouse:Boolean (default = true ) — If true , the Mouse cursor will be hidden when the custom cursor is used.
| |
xOffset:Number (default = 0 ) — The number of pixels to offset the custom cursor horizontally, measured from the Mouse position.
| |
yOffset:Number (default = 0 ) — The number of pixels to offset the custom cursor vertically, measured from the Mouse position.
| |
autoRotate:Boolean (default = true ) — To automatically rotate the cursor based on its position on the selection, set autoRotate to true .
|
deleteSelection | () | method |
public function deleteSelection($e:Event = null):void
Deletes all selected items.
Parameters
$e:Event (default = null ) — Accepts an optional Event in case you want to use this as an event handler
|
deselectAll | () | method |
public function deselectAll():void
Deselects all items
deselectItem | () | method |
public function deselectItem($item:*):TransformItem
Deselects a TransformItem or DisplayObject.
Parameters
$item:* — The TransformItem or DisplayObject that should be deselected
|
TransformItem — The TransformItem that was deselected
|
destroy | () | method |
public function destroy():void
Destroys the TransformManager instance, removing all items and preparing it for garbage collection
exportFullXML | () | method |
public function exportFullXML():XML
A common request is to capture the current state of each item's scale/rotation/position and the TransformManager's
settings in an easy-to-store format so that the data can be reloaded and applied later; exportFullXML()
returns an XML object containing exactly that. The TransformManager's settings and each item's transform data is
stored in the following format:
XML — An XML representation of the current state of the TransformManager instance and all of the items it is managing.
|
See also
<transformManager> <settings allowDelete="1" allowMultiSelect="1" autoDeselect="1" constrainScale="0" lockScale="1" scaleFromCenter="0" lockRotation="0" lockPosition="0" arrowKeysMove="0" forceSelectionToFront="1" lineColor="3381759" handleColor="16777215" handleSize="8" paddingForRotation="12" hideCenterHandle="0"/> <items> <item name="mc1" level="1" a="0.9999847412109375" b="0" c="0" d="0.9999847412109375" tx="79.2" ty="150.5" xOffset="-23.4" yOffset="-34.35" rawWidth="128.6" rawHeight="110.69999999999999" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"/> <item name="mc2" level="18" a="0.7987213134765625" b="0.2907257080078125" c="-0.2907257080078125" d="0.7987213134765625" tx="222.5" ty="92.25" xOffset="0" yOffset="0" rawWidth="287.85" rawHeight="215.8" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"/> <item name="text_ti" level="4" a="1" b="0" c="0" d="1" tx="32" ty="303.95" xOffset="-2" yOffset="-2" rawWidth="188" rawHeight="37.2" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"/> </items> </transformManager>
You can use applyFullXML() to reapply the exported XML.
exportItemXML | () | method |
public function exportItemXML(targetObject:DisplayObject):XML
Exports transform data (scale/rotation/position) of a particular DisplayObject in XML format so that
it can be saved to a database or elsewhere easily and then reapplied later. If you'd like to export all
settings and every item's data, use the exportFullXML()
instead. exportItemXML()
returns an XML object in the following format:
Parameters
targetObject:DisplayObject — The DisplayObject whose transform data you'd like to export.
|
XML — An XML object describing the targetObject's transform data (scale/rotation/position) and a few other TransformManager-related settings.
|
See also
<item name="mc1" level="1" a="0.98" b="0" c="0" d="0.9" tx="79.2" ty="150.5" xOffset="-23.4" yOffset="-34.35" rawWidth="128.6" rawHeight="110.7" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"/>
exportSettingsXML | () | method |
public function exportSettingsXML():XML
Exports the TransformManager's settings in XML format so that it can be saved to a database or elsewhere easily
and then reapplied later. exportSettingsXML()
returns an XML object in the following format:
XML — An XML object containing settings data about the TransformManager.
|
See also
<settings allowDelete="1" allowMultiSelect="1" autoDeselect="1" constrainScale="0" lockScale="1" scaleFromCenter="0" lockRotation="0" lockPosition="0" arrowKeysMove="0" forceSelectionToFront="1" lineColor="3381759" handleColor="16777215" handleSize="8" paddingForRotation="12" hideCenterHandle="0"/>
flipSelectionHorizontal | () | method |
public function flipSelectionHorizontal():void
Flips the selected items horizontally
flipSelectionVertical | () | method |
public function flipSelectionVertical():void
Flips the selected items vertically
getItem | () | method |
public function getItem($targetObject:DisplayObject):TransformItem
Gets the TransformItem associated with a particular DisplayObject (if any). This can be useful if you need to set item-specific properties like minScaleX/maxScaleX, etc.
Parameters
$targetObject:DisplayObject — The DisplayObject with which the TransformItem is associated
|
TransformItem — The associated TransformItem
|
getSelectionBounds | () | method |
public function getSelectionBounds(targetCoordinateSpace:DisplayObject = null):Rectangle
Gets the bounding Rectangle of the current selection (not including handles)
Parameters
targetCoordinateSpace:DisplayObject (default = null ) — The display object that defines the coordinate system to use.
|
Rectangle — Bounding Rectangle of the current selection (not including handles).
|
getSelectionBoundsWithHandles | () | method |
public function getSelectionBoundsWithHandles(targetCoordinateSpace:DisplayObject = null):Rectangle
Gets the bounding Rectangle of the current selection (including handles)
Parameters
targetCoordinateSpace:DisplayObject (default = null ) — The display object that defines the coordinate system to use.
|
Rectangle — Bounding Rectangle of the current selection (including handles)
|
getSelectionCenter | () | method |
public function getSelectionCenter():Point
Gets the center point of the current selection
ReturnsPoint — Center Point of the current selection
|
getUnrotatedSelectionHeight | () | method |
public function getUnrotatedSelectionHeight():Number
Gets the height of the selection as if it were not rotated.
ReturnsNumber — The unrotated selection height
|
getUnrotatedSelectionWidth | () | method |
public function getUnrotatedSelectionWidth():Number
Gets the width of the selection as if it were not rotated.
ReturnsNumber — The unrotated selection width
|
isSelected | () | method |
public function isSelected($item:*):Boolean
Determines whether or not a particular DisplayObject or TranformItem is currently selected.
Parameters
$item:* — The TransformItem or DisplayObject whose selection status needs to be checked
|
Boolean — If true, the item/DisplayObject is currently selected
|
moveSelection | () | method |
public function moveSelection($x:Number, $y:Number, $dispatchEvents:Boolean = true):void
Moves the selected items by a certain number of pixels on the x axis and y axis
Parameters
$x:Number — Number of pixels to move the selected items along the x-axis (can be negative or positive)
| |
$y:Number — Number of pixels to move the selected items along the y-axis (can be negative or positive)
| |
$dispatchEvents:Boolean (default = true ) — If false, no MOVE Events will be dispatched
|
moveSelectionDepthDown | () | method |
public function moveSelectionDepthDown():void
Moves the selection down one level.
moveSelectionDepthUp | () | method |
public function moveSelectionDepthUp():void
Moves the selection up one level.
removeAllItems | () | method |
public function removeAllItems():void
Removes all items from the TransformManager instance. This does NOT delete the items - it just prevents them from being affected by this TransformManager anymore.
removeIgnoredObject | () | method |
public function removeIgnoredObject($object:DisplayObject):void
Removes an ignored DisplayObject so that its clicks are no longer ignored.
Parameters
$object:DisplayObject — DisplayObject that should not be ignored anymore
|
removeItem | () | method |
public function removeItem($item:*):void
Removes an item. Calling this on an item will NOT delete the DisplayObject - it just prevents it from being affected by this TransformManager anymore.
Parameters
$item:* — Either the DisplayObject or the associated TransformItem that should be removed
|
removeSelectionBoxElement | () | method |
public function removeSelectionBoxElement(element:DisplayObject):void
Releases a DisplayObject that was attached using addSelectionBoxElement()
.
Parameters
element:DisplayObject — The DisplayObject to release
|
See also
rotateSelection | () | method |
public function rotateSelection($angle:Number, $dispatchEvents:Boolean = true):void
Rotates the selected items by a particular angle (in Radians). This is NOT an absolute value, so if one
of the selected items' rotation property is Math.PI and you rotateSelection(Math.PI)
, the new
angle would be Math.PI * 2.
Parameters
$angle:Number — Angle (in Radians) that should be added to the selected items' current rotation
| |
$dispatchEvents:Boolean (default = true ) — If false, no ROTATE events will be dispatched
|
scaleSelection | () | method |
public function scaleSelection($sx:Number, $sy:Number, $dispatchEvents:Boolean = true):void
Scales the selected items along the x- and y-axis using multipliers. Keep in mind that these are not absolute values, so if a selected item's scaleX is 2 and you scaleSelection(2, 1), its new scaleX would be 4 because 2 * 2 = 4.
Parameters
$sx:Number — Multiplier for scaling along the selection box's x-axis (which may or may not be the same as the selected item's y-axis, depending on whether or not multiple items are selected and if any are rotated)
| |
$sy:Number — Multiplier for scaling along the selection box's y-axis (which may or may not be the same as the selected item's y-axis, depending on whether or not multiple items are selected and if any are rotated)
| |
$dispatchEvents:Boolean (default = true ) — If false, no SCALE events will be dispatched
|
selectItem | () | method |
public function selectItem($item:*, $addToSelection:Boolean = false):TransformItem
Selects a particular TransformItem or DisplayObject (you must have already added the DisplayObject
to TransformManager in order for it to be selectable - use addItem()
for that)
Parameters
$item:* — The TransformItem or DisplayObject that should be selected
| |
$addToSelection:Boolean (default = false ) — If true, any currently selected items will remain selected and the new item/DisplayObject will be added to the selection.
|
TransformItem — The TransformItem that was selected.
|
selectItems | () | method |
public function selectItems($items:Array, $addToSelection:Boolean = false):Array
Selects an Array of TransformItems and/or DisplayObjects. (you must have already added the DisplayObjects
to TransformManager in order for it to be selectable - use addItem()
or addItems()
for that)
Parameters
$items:Array — An Array of TransformItems and/or DisplayObjects to be selected
| |
$addToSelection:Boolean (default = false ) — If true, any currently selected items will remain selected and the new items/DisplayObjects will be added to the selection.
|
Array — An Array of TransformItems that were selected
|
updateSelection | () | method |
public function updateSelection($centerOrigin:Boolean = true):void
Refreshes the selection box/handles.
Parameters
$centerOrigin:Boolean (default = true ) — If true, the origin (axis of rotation/scaling) will be automatically centered.
|
SCALE_NORMAL | Constant |
public static const SCALE_NORMAL:String = scaleNormal
Normal scale mode
SCALE_WIDTH_AND_HEIGHT | Constant |
public static const SCALE_WIDTH_AND_HEIGHT:String = scaleWidthAndHeight
Scale only width
and height
properties