| Package | com.soma.core.model |
| Class | public class Model |
| Inheritance | Model Object |
| Implements | IModel |
Author: Romuald Quantin - www.soundstep.com
Resources: http://www.soundstep.com/downloads/somacore
Actionscript version: 3.0
Copyright: Mozilla Public License 1.1 (MPL 1.1) http://www.opensource.org/licenses/mozilla1.1.php
The model is the class used to manage you application's data model.
The data can be XML, local data, data retrieved from a server or anything. Ideally, the data should be set to the data property of the model instance, but you are free to create specific getters.
See also
| Property | Defined By | ||
|---|---|---|---|
| data : Object
Data of the model. | Model | ||
| dispatcher : IEventDispatcher
EventDispatcher instance of the model. | Model | ||
| Property | Defined By | ||
|---|---|---|---|
| _data : Object
Variable that can be used to hold you data. | Model | ||
| _dispatcher : IEventDispatcher
Instance of a EventDispatcher that can be used to dispatch commands. | Model | ||
| _name : String
Name of the model. | Model | ||
| Method | Defined By | ||
|---|---|---|---|
Model(name:String = null, data:Object = null, dispatcher:IEventDispatcher = null)
Create an instance of a Model class. | Model | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | Model | ||
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow. | Model | ||
dispose():void
Method that can you can override, called when the model has been removed from the framework. | Model | ||
getName():String
Retrieves the name of the model. | Model | ||
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | Model | ||
initialize():void
Method that can you can override, called when the model has been registered to the framework. | Model | ||
postConstruct():void | Model | ||
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object. | Model | ||
setName(value:String):void
Sets the name of the model. | Model | ||
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | Model | ||
| _data | property |
protected var _data:ObjectVariable that can be used to hold you data.
The default value is null;.
| _dispatcher | property |
protected var _dispatcher:IEventDispatcherInstance of a EventDispatcher that can be used to dispatch commands.
The default value is Framework instance (Soma instance)..
| _name | property |
protected var _name:StringName of the model.
| data | property |
data:ObjectData of the model.
public function get data():Object public function set data(value:Object):void| dispatcher | property |
dispatcher:IEventDispatcherEventDispatcher instance of the model.
The default value is The framework instance..
public function get dispatcher():IEventDispatcher public function set dispatcher(value:IEventDispatcher):void| Model | () | Constructor |
public function Model(name:String = null, data:Object = null, dispatcher:IEventDispatcher = null)Create an instance of a Model class. The Model class should be extended.
Parametersname:String (default = null) — Name of the model.
| |
data:Object (default = null) — Data of the model.
| |
dispatcher:IEventDispatcher (default = null) — EventDispatcher instance that can be used to dispatch commands.
|
| addEventListener | () | method |
public final function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):voidRegisters an event listener object with an EventDispatcher object so that the listener receives notification of an event.
Parameters
type:String — The type of event.
| |
listener:Function — The listener function that processes the event.
| |
useCapture:Boolean (default = false) — Determines whether the listener works in the capture phase or the target and bubbling phases.
| |
priority:int (default = 0) — The priority level of the event listener.
| |
useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak.
|
| dispatchEvent | () | method |
public final function dispatchEvent(event:Event):BooleanDispatches an event into the event flow. The event target is the EventDispatcher object upon which dispatchEvent() is called.
Parameters
event:Event — The event object dispatched into the event flow.
|
Boolean — A value of true unless preventDefault() is called on the event, in which case it returns false.
|
| dispose | () | method |
public function dispose():voidMethod that can you can override, called when the model has been removed from the framework.
| getName | () | method |
public function getName():StringRetrieves the name of the model.
ReturnsString — A String.
|
| hasEventListener | () | method |
public final function hasEventListener(type:String):BooleanChecks whether the EventDispatcher object has any listeners registered for a specific type of event.
Parameters
type:String — The type of event.
|
Boolean — A value of true if a listener of the specified type is registered; false otherwise.
|
| initialize | () | method |
public function initialize():voidMethod that can you can override, called when the model has been registered to the framework.
| postConstruct | () | method |
public function postConstruct():void| removeEventListener | () | method |
public final function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):voidRemoves a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.
Parameters
type:String — The type of event.
| |
listener:Function — The listener object to remove.
| |
useCapture:Boolean (default = false) — Specifies whether the listener was registered for the capture phase or the target and bubbling phases.
|
| setName | () | method |
public function setName(value:String):voidSets the name of the model.
Parameters
value:String — A String.
|
| willTrigger | () | method |
public final function willTrigger(type:String):BooleanChecks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
Parameters
type:String — The type of event.
|
Boolean — A value of true if a listener of the specified type will be triggered; false otherwise.
|
package {
import com.soma.core.interfaces.IModel;
import com.soma.core.model.Model;
public class ModelExample extends Model implements IModel {
public static const NAME:String = "Model example name";
public function ModelExample() {
super(NAME);
}
override public function initialize():void {
// called when the model has been registered to the framework
data = new XML('<myXML/>');
// you can use the model as a dispatcher (default dispatcher is the framework instance) to dispatch commands, example:
dispatchEvent(new MyEvent(MyEvent.DATA_READY));
}
override public function dispose():void {
// called when the model has been removed from the framework
data = null;
}
}
}
addModel(ModelExample.NAME, new ModelExample());
removeModel(ModelExample.NAME);
var model:ModelExample = getModel(ModelExample.NAME) as ModelExample;
private function get modelExample():ModelExample {
return getModel(ModelExample.NAME) as ModelExample;
}
private function doSomething():void {
trace(modelExample.data);
}