forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathalignRight.as
More file actions
59 lines (55 loc) · 1.24 KB
/
alignRight.as
File metadata and controls
59 lines (55 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package utils.align
{
/**
* Aligns all the target DisplayObjects by their left edge to the left-most target.
*
* Similar to the Flash IDE Alignment panel.
*
* Given the following arrangement of targets:
* <code>
* t1
* t2
* t3
* </code>
*
* After calling <code>alignRight([ t1, t2, t3 ])</code> the arrangment will be:
* <code>
* t1
* t2
* t3
* </code>
*
* @param targets Array of DisplayObject
* or Object with an <code>x</code> property like <code>Point</code>
* or Object with an <code>x</code> and <code>width</code> properties like <code>Rectangle</code>.
*
* @return targets Array.
*
* @example
* <listing version="3.0">
*
* </listing>
*
* @author drewbourne
*/
public function alignRight(targets:Array):Array
{
var maxX:Number = Number.MIN_VALUE;
var targetW:Number;
var targetX:Number;
var target:Object;
for each (target in targets)
{
targetW = "width" in target ? target["width"] : 0;
targetX = target.x + targetW;
if (targetX > maxX)
maxX = targetX;
}
for each (target in targets)
{
targetW = "width" in target ? target["width"] : 0;
target.x = maxX - targetW;
}
return targets;
}
}