﻿
Visit www.gskinner.com/blog for documentation, updates and more free code.


****************************************************************************

WeakReference:
Creates a weak reference to any object. The get() method returns a refence to the object.

var weakRef:WeakReference = new WeakReference(myObj);
delete(myObj);
weakRef.get().doSomething(); // calls doSomething on the weakly referenced object (ex. myObj)
weakRef.get().foo = 20; // sets the value of the property foo on the referent

****************************************************************************

WeakProxyReference:
Creates a proxied weak reference to any object. Instead of having to use get() to access the object, you can call methods and access properties on the proxy directly.

var weakRef:WeakReference = new WeakReference(myObj);
delete(myObj);
weakRef.doSomething(); // calls doSomething on the weakly referenced object (ex. myObj)
weakRef.foo = 20; // sets the value of the property foo on the referent

****************************************************************************

IDisposable:
Interface that indicates that an object has a dispose() method. The dispose method should carry out any tasks necessary to prepare the object for collection (ex. removing listeners, stopping sounds, etc).

public class implements IDisposable {
	public function dispose():void {
		// clean up here.
	}
}

****************************************************************************

StageStatusNotifier:
Adds "addedToStage" and "removedFromStage" events to DisplayObjects.

// in a displayobject class:
myNotifier = new StageStatusNotifier(this);
addEventListener(StageStatusNotifier.ADDED_TO_STAGE,handleAddedToStage);

****************************************************************************

Janitor:
Cleans up most common elements of an object, including:
* remove event listeners
* unload any swf's that were loaded so they can also clean up on unload
* close any LocalConnections, NetConnections, NetStreams, XML, Sockets, etc
* stop any sound channels from playing
* stop any running multiframe movieclips on the time line
* stop the timeline if multiframe and playing
* clear intervals, clear timeouts, stop Timers

myJanitor = new Janitor(this);
myJanitor.addConnection(myNetStream);
// etc.
...
// in dispose():
myJanitor.cleanUp();