Packageorg.spicefactory.lib.task
Classpublic class ResultTask
InheritanceResultTask Inheritance Task Inheritance flash.events.EventDispatcher
Subclasses XmlLoaderTask

Abstract base class for asynchronous operations that produce a result. This may be a loading operation or a remote service invocation.

With the optional propertyName parameter of the constructor you can specify a property that will be set in the value of the data property. Since the data 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 data 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.data = 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.data 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 data property.



Public Properties
 PropertyDefined By
 Inheritedcancelable : Boolean
[read-only] Indicates whether this Task can be cancelled.
Task
 Inheriteddata : *
An arbitrary value associated with this Task.
Task
 Inheritedparent : TaskGroup
[read-only] The parent of this Task.
Task
 Inheritedrestartable : Boolean
[read-only] Indicates whether this Task can be restarted.
Task
  result : *
[read-only] The result produced by this Task.
ResultTask
 Inheritedroot : Task
[read-only] The root TaskGroup in case this Task is nested in one or more TaskGroups.
Task
 Inheritedskippable : Boolean
[read-only] Indicates whether this Task can be forced to skip to its final state.
Task
 Inheritedstate : TaskState
[read-only] The current state of this Task.
Task
 Inheritedsuspendable : Boolean
[read-only] Indicates whether this Task can be suspended.
Task
 Inheritedtimeout : uint
[read-only] The timeout for this Task in milliseconds.
Task
Public Methods
 MethodDefined By
  
ResultTask(propertyName:String = null)
Creates a new ResultTask instance.
ResultTask
 Inherited
cancel():Boolean
Cancels this Task.
Task
 Inherited
resume():Boolean
Resumes this Task if it is suspended.
Task
 Inherited
skip():Boolean
Forces this Task to move to its final state.
Task
 Inherited
start():Boolean
Starts this Task.
Task
 Inherited
suspend():Boolean
Suspends this Task.
Task
Protected Methods
 MethodDefined By
 Inherited
complete():Boolean
Signals that this Task has completed.
Task
 Inherited
doCancel():void
Called before the CANCEL event gets fired.
Task
 Inherited
doError(message:String):void
Called before the ERROR event gets fired.
Task
 Inherited
doResume():void
Called before the RESUME event gets fired.
Task
 Inherited
doSkip():void
Called after skip has been called but before the COMPLETE event gets fired.
Task
 Inherited
doStart():void
Called before the START event gets fired.
Task
 Inherited
doSuspend():void
Called before the SUSPEND event gets fired.
Task
 Inherited
doTimeout():void
Called before the ERROR event gets fired after a timeout occurred.
Task
 Inherited
error(message:String):Boolean
Signals an error condition and cancels the Task.
Task
 Inherited
setCancelable(value:Boolean):void
Specifies whether this Task can be cancelled.
Task
 Inherited
setName(name:String):void
Sets the name of this Task.
Task
 Inherited
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
 Inherited
setSkippable(value:Boolean):void
Specifies whether this Task can be forced to skip to its final state.
Task
 Inherited
setSuspendable(value:Boolean):void
Specifies whether this Task can be suspended.
Task
 Inherited
setTimeout(value:uint):void
Sets the timeout for this Task in milliseconds.
Task
Events
 Event Summary Defined By
 InheritedDispatched when a Task is cancelled.Task
 InheritedDispatched when a Task has completed its execution.Task
 InheritedDispatched when a Task has aborted due to an error condition.Task
 InheritedDispatched when a suspended Task is resumed.Task
 InheritedDispatched when a Task is started.Task
 InheritedDispatched when a Task is suspended.Task
Property Detail
resultproperty
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():*
Constructor Detail
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 data property of this Task or one of its parents.

Parameters
propertyName:String (default = null)
Method Detail
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.

Parameters

result:*

Returns
Boolean — true if the Task successfully switched its internal state, false if otherwise