My favorites | Sign in
Project Logo
                
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
* ...
* @author Troy Gardner
* @version 0.1
*/

package com.troyworks.ui {
import flash.system.ApplicationDomain;
import flash.media.Sound;
import flash.display.Sprite;
import flash.display.InteractiveObject;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;

public class UIUtil {
protected var clipsToWatch : Array;
var hidx : Object = new Object();

public function UIUtil(clipsToEffect : Array) {
this.clipsToWatch = clipsToEffect;
}

///// these are useful for printing ///////
public function hide() : void {
var hide2 : Array = clipsToWatch.concat();
var o : Object;
while(hide2.length > 0) {
o = hide2.pop();
if(o != null) {
trace("hidthing " + o.name);
hidx[o.name] = o.visible;
o.visible = false;
}
}
}

public function resetVisibility() : void {
var hide2 : Array = clipsToWatch.concat();
var o : Object;
while(hide2.length > 0) {
o = hide2.pop();
if(o != null) {
trace("resettinging " + o.name + " " + hidx[o.name]);

o.visible = hidx[o.name];
}
}
}

public function release() : void {
while(clipsToWatch.length > 0) {
clipsToWatch.pop();
}
}
/* get a Sound object by the linkageID from the UI.fla */
public static function getSoundByLinkageID(soundLinkageId : String) : Sound {
var cls : Class = ApplicationDomain.currentDomain.getDefinition(soundLinkageId) as Class;
var snd : Sound = new cls() as Sound;
return snd;
}
/* get a DisplayObject object by the linkageID from the UI.fla */
public static function getDisplayObjectByLinkageID(soundLinkageId : String) : DisplayObject {
var cls : Class = ApplicationDomain.currentDomain.getDefinition(soundLinkageId) as Class;
var dO : DisplayObject = new cls() as DisplayObject; ;
return dO;
}

/* returns the zero based frame label to be used in conjunctin with addFrameScript */

public static function getNumberOfFrameLabel(mc : MovieClip, lblName : String) : int {
var nm : String;
var fn : int;
for (var i : int = 0;i < mc.currentLabels.length; i++) {
nm = mc.currentLabels[i].name;
fn = mc.currentLabels[i].frame;
if(nm == lblName) {
trace(" " + nm + " " + ( fn - 1));
return fn - 1;
}
}
return -1;
}

public static function addFrameScriptForLabel(mc : MovieClip, lblName : String, fn : Function ) : int {
var frameNum : int = UIUtil.getNumberOfFrameLabel(mc, lblName);
mc.addFrameScript(frameNum, fn);
return frameNum;
}

public static function setInputShieldBehavior(sprite : Sprite, ON : Boolean = true) : void {
if(ON) {
sprite.buttonMode = true;
sprite.mouseChildren = false;
sprite.useHandCursor = false;
}else {
sprite.buttonMode = false;
sprite.mouseChildren = true;
sprite.useHandCursor = true;
}
}

public static function getMouseAngle(disObjCon : DisplayObjectContainer) : Number {
return Math.atan2(disObjCon.parent.mouseY - disObjCon.y, disObjCon.parent.mouseX - disObjCon.x) * 180 / Math.PI;
};


public static function match(changeClip : DisplayObject, toClip : DisplayObject, withProps : Array = null) : void {

if (withProps == null) {
withProps = [null, "alpha", "visible", "rotation", "scaleX", "scaleY", "x", "y"];
}
var L : Number = withProps.length;
while (--L) {
changeClip[withProps[L]] = toClip[withProps[L]];
}
}

/***********************************
* Used in sort operations
* **********************************/
public static function order_X(a : DisplayObject, b : DisplayObject) : Number {
if (a.x < b.x) {
return -1;
} else if (a.x > b.x) {
return 1;
} else {
return 0;
}
}

public static function order_Y(a : DisplayObject, b : DisplayObject) : Number {
if (a.y < b.y) {
return -1;
} else if (a.y > b.y) {
return 1;
} else {
return 0;
}
}

/********************************************************
* This traverses the parent.parent chain of a displaylist
* appending the name of a clip
* it's useful for absolute pathing a given leave
* for debugging and for associating dynamic data with it
* */
public static function getFullPath(child : DisplayObject, showRoot : Boolean = false) : String {
var cur : DisplayObject = child;
var pathA : Array = new Array();
var res : String;
while(cur.parent != null) {
//trace("parent" + cur.parent);
if(cur.parent != null) {
pathA.push(cur.name);
if(!showRoot && cur.parent == cur.stage) {
break;
}else {
cur = cur.parent;
}
}
}
pathA.reverse();
trace("res " + res);
res = pathA.join(".");
return res;
}

/*
* will return if the passed in clip distance from the local root
* note in the case of multiple swfs, they have their own independent roots.
* nominally should be 1, as
* by the maintimeline/root> passed in clip
*/

public static function getDepthFromRoot(child : DisplayObject) : int {
var cur : DisplayObject = child;
var res : int = 1;
while(cur.parent != null) {
if(cur.parent != null) {
res++;
//trace(cur + "'s parent is " + cur.parent);
if(cur.parent == cur.root) {
break;
}else {

cur = cur.parent;
}
}
}
return res;
}

/*
* will return if the passed in clip is a top level clip as defined
* by the stage>maintimeline/root> passed inclip
* this is useful to avoid library collisions/contentions
*/
public static function isTopLevel(child : DisplayObject) : Boolean {
return getDepthFromStage(child) == 2;
}

/*
* will return if the passed in clip distance from the stage
* nominally should be 2, as
* by the stage>maintimeline/root> passed in clip
*/

public static function getDepthFromStage(child : DisplayObject) : int {
var cur : DisplayObject = child;
var res : int = 1;
while(cur.parent != null) {
if(cur.parent != null) {
res++;
trace(cur + "'s parent is " + cur.parent);
if(cur.parent == cur.stage) {
break;
}else {

cur = cur.parent;
}
}
}
return res;
}
}
}
Show details Hide details

Change log

r67 by TroyWorks on Feb 11, 2009   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r52 by TroyWorks on Nov 09, 2008   Diff
[No log message]
r32 by TroyWorks on Aug 05, 2008   Diff
LayoutUtil.as had an erroneous check
against Num== NaN, should be
isNaN(num);   UIUtil.as adding a
utility to addAFrameScript to a
labelled frame
r7 by TroyWorks on May 29, 2008   Diff
Adding the correct version of the main
source tree.
All revisions of this file

File info

Size: 6530 bytes, 229 lines
Hosted by Google Code