org. helvector. util. Housekeeper

Summary
Class to track any object that’s registered to listen to an event and is created by a movieclip.
Makes sure it’s possilbe to attach a new onUnload event without destroying another.
Singleton patterned instance creation, each movieclip will only take one instance of a Housekeeper.
kills all events registered for garbage collection.
Removes a registered garbage object from the collection list.

Notes

Class to track any object that’s registered to listen to an event and is created by a movieclip.  Once registered it will automatically tidy up, or garbage collect, when that movieclip is unloaded.  Legitamate events include,

  • Any Observer/Event Listener that is registered to recieve events from outside the movie clip scope.  Ie this.a:Observer registers with _parent.b:Observable
  • Interval (timer)
  • Key
  • Mouse
  • Selection (txt field and movie input focus)
  • Stage
  • TextField

Vunerable to be having it’s onUnload method overwritten.  Any ideas on countering this?

Extensions should be, added to include the optional registering of an unload function, or functions to be executed along with this one.

will need to provide and Housekeeping interface for classes to implement when adding and removing and “memory hog” linked objects..

Variables

_instance

public static var _instance: Housekeeper

myMc

private static var myMc: MovieClip

a

private var a: Array

LeavingMessage

public static var LeavingMessage: String

Functions

Housekeeper

Empty Constructoronly create instances with getInstance;

startKeeping

function startKeeping():Boolean

Makes sure it’s possilbe to attach a new onUnload event without destroying another.  Traces or Logs an error message on Fail.

Parameters

None.

Returns

Boolean

Variables

me

var me: Housekeeper

Functions

getInstance

public function getInstance(mc: MovieClip):Housekeeper

Singleton patterned instance creation, each movieclip will only take one instance of a Housekeeper.

Parameters

mcMovieclip to create the new housekeeper inside.

Returns

An instance of Housekeeper

See Also

Nothing

killAll

public function killAll():Boolean

kills all events registered for garbage collection.

Parameters

None

Returns

True on success, False on failure.

addGarbage

public function addGarbage(ob: Object,
a: Array):Boolean

removeGarbage

private function removeGarbage(ob: Observer):Boolean

Removes a registered garbage object from the collection list.

Parameters

obobject registered for garbage removal

Returns

True on successful removal, False when the object’s not been found.

public static var _instance: Housekeeper
private static var myMc: MovieClip
private var a: Array
public static var LeavingMessage: String
function startKeeping():Boolean
Makes sure it’s possilbe to attach a new onUnload event without destroying another.
var me: Housekeeper
public function getInstance(mc: MovieClip):Housekeeper
Singleton patterned instance creation, each movieclip will only take one instance of a Housekeeper.
public function killAll():Boolean
kills all events registered for garbage collection.
public function addGarbage(ob: Object,
a: Array):Boolean
private function removeGarbage(ob: Observer):Boolean
Removes a registered garbage object from the collection list.