class AFrame.AObject
The base object of nearly everything. It is recommended to create all new classes as a subclass of AObject since it provides general functionality such as event binding and teardown housekeeping. All AObjects in the system have a cid, a cid is a unique identifier within the application. If an AObject creates and is responsible for maintaining other AObjects, addChild should be called with the created children. When this object is torn down, the child object added via addChild will have its teardown function called as well. This can ensure that all memory is freed and that no references are kept when the object's lifespan has ended.
Declaring Configuration Items to Import
A very common pattern used in AFrame derived objects is to save off a list of configuration options that an object is created with. Each class can define a list of configuration options that should automatically be imported on object creation.
Example Auto-Import of Configuration Items
// Define a class with items to import
var SomeClass = AFrame.Class( {
importconfig: [ 'firstImportedParam', 'secondImportedParam' ]
} );
var someClassInst = SomeClass.create( {
firstImportedParam: "This is imported",
secondImportedParam: "So is this",
thirdParam: "But this is not"
} );
Event Usage
All AFrame.AObject based classes have a built in event mechanism. Events are dynamically created, there is no need to explicitly create an event, all that is needed is to call the object's triggerEvent or bindEvent.
Event Example Usage:
// Assume anObject is an AFrame.AObject based object.
// Every AFrame.AObject based object triggers an onInit event
// when its init function is called.
var onObjectInit = function() {
// called whenever anObject.init is called.
};
anObject.bindEvent( 'onInit', onObjectInit );
anObject.init(); // calls onObjectInit function
Declaring Event Bindings
Binding to dependent object's events is another common pattern used in AFrame. To make this process simpler, it is possible to declare event bindings. When declaring event bindings, three pieces of information are needed, the event name, the name of the object that is triggering the event, and the function (or name of the member function to bind as a handler.
Example Usage:
// bind to two events on insertedObj, event1, and event2.
// event1 has an inline handler.
// event2 uses a class member as a handler.
var Class = AFrame.AObject.extend( {
importconfig: [ 'insertedObj' ],
events: {
'event1 insertedObj': function() {
// Handle event here
},
'event2 insertedObj': 'event2Handler'
},
event2Handler: function() {
// handle event here
}
} );
Uses…
Known subclasses
Methods
| Methods | Returns | Description |
|---|---|---|
addChild(
child
)
|
void
|
↑
Add a child. All children are torn down on this object's teardown
Parameters:
|
bindEvents(
)
|
void
|
↑
Override to do any event binding |
getCID(
)
|
void
|
↑
Get the CID of the object
|
getConfig(
)
|
object
|
↑
Return the configuration object given in init.
Returns:
|
init(
config
)
|
void
|
↑
Initialize the object. Note that if a class' create static function is used to create an object, this will be called automatically.
Parameters:
|
removeChild(
cid
)
|
void
|
↑
Remove a child.
Parameters:
|
teardown(
)
|
void
|
↑
Tear the object down, free any references
|
triggerProxy(
eventName
)
|
void
|
↑
Create a trigger event proxy function. Useful to re-broadcast an event or when a DOM event should trigger a normal AObject based event.
Parameters:
|
Methods inherited from AFrame.ObservablesMixin
| Methods | Notes |
|---|---|
bindEvent
|
↑ |
bindTo
|
↑ |
getEventObject
|
↑ |
isEventTriggered
|
↑ |
proxyEvents
|
↑ |
setEventData
|
↑ |
triggerEvent
|
↑ |
unbindAll
|
↑ |
unbindEvent
|
↑ |
unbindTo
|
↑ |
unbindToAll
|
↑ |
Events
| Events | Description |
|---|---|
onInit(
event
)
|
↑
Triggered when the object is initialized Parameters:
|
onTeardown(
event
)
|
↑
triggered whenever tte object is torn down Parameters:
|