Files
narya/src/as/com/threerings/util/WeakReference.as
T
Ray Greenwell dbf20bdc28 WeakReference. Apply directly to the forehead.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5725 542714f4-19e9-0310-aa3c-eee0fc999fb1
2009-04-16 22:53:35 +00:00

37 lines
710 B
ActionScript

//
// $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);
}
}