Implemented DisplayUtil.applyToHierarchy, because the similar function

included in the mx library is unable to cope with security errors
accessing a child.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4444 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-11-03 22:34:10 +00:00
parent 9ef2673464
commit ce2c276d87
2 changed files with 37 additions and 2 deletions
@@ -23,7 +23,7 @@ package com.threerings.crowd.client {
import flash.display.DisplayObject;
import mx.utils.DisplayUtil;
import com.threerings.util.DisplayUtil;
import com.threerings.crowd.data.PlaceObject;
@@ -72,7 +72,7 @@ public class PlaceViewUtil
return;
}
DisplayUtil.walkDisplayObjects(root as DisplayObject,
DisplayUtil.applyToHierarchy(root as DisplayObject,
function (disp :DisplayObject) :void {
if (disp is PlaceView) {
try {
+35
View File
@@ -1,10 +1,45 @@
package com.threerings.util {
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.geom.Point;
import flash.geom.Rectangle;
import mx.core.IChildList;
import mx.core.IRawChildrenContainer;
public class DisplayUtil
{
/**
* Call the specified function for the display object and all descendants.
*
* This is nearly exactly like mx.utils.DisplayUtil.walkDisplayObjects,
* except this method copes with security errors when examining a child.
*/
public static function applyToHierarchy (
disp :DisplayObject, callbackFunction :Function) :void
{
callbackFunction(disp);
if (disp is DisplayObjectContainer) {
// a little type-unsafety so that we don't have to write two blocks
var o :Object = (disp is IRawChildrenContainer) ?
IRawChildrenContainer(disp).rawChildren : disp;
var nn :int = int(o.numChildren);
for (var ii :int = 0; ii < nn; ii++) {
try {
disp = DisplayObject(o.getChildAt(ii));
} catch (err :SecurityError) {
continue;
}
// and then we apply outside of the try/catch block so that
// we don't hide errors thrown by the callbackFunction.
applyToHierarchy(disp, callbackFunction);
}
}
}
/**
* Returns the most reasonable position for the specified rectangle to
* be placed at so as to maximize its containment by the specified