| Package | org.spicefactory.lib.task |
| Class | public class ResultTask |
| Inheritance | ResultTask Task flash.events.EventDispatcher |
With the optional propertyName parameter of the constructor you
can specify a property that will be set in the value of the context property.
Since the context property of any Task is recursive (if it wasn't set for a particular Task it uses the
value of its parent TaskGroup), you can use an object that was set as the context property
on a containing TaskGroup to collect values of different ResultTasks. This way you don't have
to keep references to all individual Tasks just to retrieve the result after the asynchronous
operation is finished.
In the following example a simple value object will be used to collect the loaded text and XML of two loader tasks:
public class LoaderResult {
public var text:String;
public var xml:XML;
}
var group:TaskGroup = new SequentialTaskGroup();
group.context = new LoaderResult();
group.addTask(new TextLoaderTask("test.txt", "text"));
group.addTask(new XmlLoaderTask("test.xml", "xml"));
group.addEventListener(TaskEvent.COMPLETE, onComplete);
// error handling omitted
group.start();
private function onComplete (event:TaskEvent) : void {
var t:Task = event.target as Task;
var result:LoaderResult = t.context as LoaderResult;
trace("loaded text: " result.text);
trace("loaded XML: " result.xml);
}
Note that the two loader tasks of the above example (TextLoaderTask and
XmlLoaderTask) are not part of the Spicelib (yet). They are just used for
illustration purposes. This example only works if the constructor of these two classes
passes the second argument to the constructor of the superclass (ResultTask).
Instead of a concrete class like LoaderResult in the
example above you can also use a simple Dictionary as the context property.
| Property | Defined by | ||
|---|---|---|---|
![]() | cancelable : Boolean
Indicates whether this Task can be cancelled.
| Task | |
![]() | context : *
An arbitrary value associated with this Task.
| Task | |
![]() | parent : TaskGroup
The parent of this Task.
| Task | |
![]() | restartable : Boolean
Indicates whether this Task can be restarted.
| Task | |
| result : * [read-only]
The result produced by this Task.
| ResultTask | ||
![]() | skippable : Boolean
Indicates whether this Task can be forced to skip to its final state.
| Task | |
![]() | state : TaskState
The current state of this Task.
| Task | |
![]() | suspendable : Boolean
Indicates whether this Task can be suspended.
| Task | |
![]() | timeout : uint
The timeout for this Task in milliseconds.
| Task | |
| Method | Defined by | ||
|---|---|---|---|
|
ResultTask(propertyName:String = null)
Creates a new ResultTask instance.
| ResultTask | ||
![]() |
cancel():Boolean
Cancels this Task.
| Task | |
![]() |
resume():Boolean
Resumes this Task if it is suspended.
| Task | |
![]() |
skip():Boolean
Forces this Task to move to its final state.
| Task | |
![]() |
start():Boolean
Starts this Task.
| Task | |
![]() |
suspend():Boolean
Suspends this Task.
| Task | |
| Method | Defined by | ||
|---|---|---|---|
![]() |
complete():Boolean
Signals that this Task has completed.
| Task | |
![]() |
doCancel():void
Called before the
CANCEL event gets fired. | Task | |
![]() |
doError(message:String):void
Called before the
ERROR event gets fired. | Task | |
![]() |
doResume():void
Called before the
RESUME event gets fired. | Task | |
![]() |
doSkip():void
Called after
skip has been called but before the COMPLETE event gets fired. | Task | |
![]() |
doStart():void
Called before the
START event gets fired. | Task | |
![]() |
doSuspend():void
Called before the
SUSPEND event gets fired. | Task | |
![]() |
doTimeout():void
Called before the
ERROR event gets fired after a timeout occurred. | Task | |
![]() |
error(message:String):Boolean
Signals an error condition and cancels the Task.
| Task | |
![]() |
setCancelable(value:Boolean):void
Specifies whether this Task can be cancelled.
| Task | |
![]() |
setName(name:String):void
Sets the name of this Task.
| Task | |
![]() |
setRestartable(value:Boolean):void
Specifies whether this Task can be restarted.
| Task | |
|
setResult(result:*):Boolean
Sets the result produced by this Task and signals that this Task has completed.
| ResultTask | ||
![]() |
setSkippable(value:Boolean):void
Specifies whether this Task can be forced to skip to its final state.
| Task | |
![]() |
setSuspendable(value:Boolean):void
Specifies whether this Task can be suspended.
| Task | |
![]() |
setTimeout(value:uint):void
Sets the timeout for this Task in milliseconds.
| Task | |
| result | property |
result:* [read-only]The result produced by this Task. If the Task has not completed yet, was cancelled or finished with an error this property is undefined.
Implementation public function get result():*
| ResultTask | () | constructor |
public function ResultTask(propertyName:String = null)
Creates a new ResultTask instance. The optional propertyName parameter
can be used to specify a property that will be set on the value of the context property
of this Task or one of its parents.
propertyName:String (default = null) |
| setResult | () | method |
protected function setResult(result:*):Boolean
Sets the result produced by this Task and signals that this Task has completed.
Subclasses should call this method
when the asynchronous operation has completed. If this method executes successfully
the COMPLETE event will be fired.
This method should be used instead of the complete method from
the Task superclass.
result:* |
Boolean — true if the Task successfully switched its internal state, false if otherwise
|