diff --git a/src/as/com/threerings/util/WeakReference.as b/src/as/com/threerings/util/WeakReference.as new file mode 100644 index 000000000..f58be3f28 --- /dev/null +++ b/src/as/com/threerings/util/WeakReference.as @@ -0,0 +1,36 @@ +// +// $Id$ + +package com.threerings.util { + +import flash.utils.Dictionary; + +/** + * A weak reference. At some point in the future the referent might not be available + * anymore. + */ +public class WeakReference +{ + /** + * No, you cannot store undefined here. + */ + public function WeakReference (referant :Object) + { + _ref[referant] = true; + } + + /** + * Return the referant, or undefined if it's been collected. + */ + public function get () :* + { + for (var k :* in _ref) { + return k; + } + return undefined; + } + + /** The only way to have a weak reference in actionscript. */ + protected var _ref :Dictionary = new Dictionary(true); +} +}