#

API Docs for: 0.0.1
Show: Inherited Protected Private Deprecated

# SequenceTask Class

Extends TaskGroup
Defined in: `../monkeybars.js:1139`

A SequenceTask is a TaskGroup that runs all of its subtasks serially. Its complete functionality is run when all of its sub tasks are complete.

## Constructor

### `SequenceTask`

(

- `attributes`

)

Defined in `../monkeybars.js:1139`

#### Parameters:

- `attributes` Object

  List of attributes to apply to the task group

#### Example:

            var sequence = new MonkeyBars.SequenceTask({
                name:"ParallelTask",
                tasks:[new MonkeyBars.Task({
                    performTask:function(){
                        this.complete();
                    }
                })],
                onComplete:function(){
                    alert(this.name + " is complete!");
                }
            });

            sequence.start();

- Index
- Methods
- Properties

## Item Index

### Methods

- addSubTask
- addSubTaskAfterTask
- addSubTaskBeforeTask
- cancel
- complete
- fault
- getTaskById
- getTaskByName
- getTaskByTid
- onCancel
- onChange
- onComplete
- onFault
- onStart
- onSubTaskCancel
- onSubTaskComplete
- onSubTaskFault
- performTask
- processSubTask
- removeSubTask
- start
- startNextSubTask

### Properties

- currentIndex
- displayName
- state
- type

## Methods

### `addSubTask`

(

- `task`

)

Inherited from TaskGroup: `../monkeybars.js:644`

Adds a subtask to the groups queue. This is helpful when you want to add a sub task after instantiation.

#### Parameters:

- `task` Object

  Either an object containing attributes of a task or an already instantiated task

#### Example:

            var parallel = new MonkeyBars.ParallelTask();

            parallel.addSubTask({
                name:"subtask",
                performTask:function(){
                    this.complete();
                }
            });

            var simple = new MonkeyBars.simple({
                name:"subtask",
                performTask:function(){
                    this.complete();
                }
            });

            parallel.addSubTask(simple);

### `addSubTaskAfterTask`

(

- `task`
- `afterTask`

)

Inherited from TaskGroup: `../monkeybars.js:684`

description

#### Parameters:

- `task` Object

  Either an object containing attributes of a task or

- `afterTask` Object

  Reference to an already added task

#### Example:

            var parallel = new MonkeyBars.ParallelTask({
                tasks:[task1,task3]
            });

            var task2 = new MonkeyBars.Task();
            parallel.addTaskAfterTask(task2,task1);

### `addSubTaskBeforeTask`

(

- `task`
- `beforeTask`

)

Inherited from TaskGroup: `../monkeybars.js:716`

Very similar to `addSubTaskAfterTask` except the inject task appears before the second arguments position.

#### Parameters:

- `task` Object

  Either an object containing attributes of a task or

- `beforeTask` Object

  Reference to an already added task

### `cancel`

()

Inherited from Task but overwritten in `../monkeybars.js:918`

Cancel the group and cancel all of its subtasks

### `complete`

()

Inherited from Task: `../monkeybars.js:391`

Calling this method says that the tasks execution is now complete.

#### Example:

            var task = new MonkeyBars.Task({
                performTask:function(){
                    this.complete();
                }
            });

            task.start();

### `fault`

(

- `error`

)

Inherited from Task: `../monkeybars.js:423`

Calling this method to fault a task. If it is part of a group task this will also call the groups fault method passing the error up to the group.

#### Parameters:

- `error` String

  Message associated with the cause of the fault.

#### Example:

            var task = new MonkeyBars.Task({
                performTask:function(){
                    var a = "a";
                    if(a != "b") {
                        this.fault("a != b");
                    }
                }
            });

            task.start();

### `getTaskById`

(

- `id`

)

Inherited from TaskGroup: `../monkeybars.js:880`

Return a Task object, if it exists, based on the `id` passed.

#### Parameters:

- `id` String

  The user defined id

### `getTaskByName`

(

- `name`

)

Inherited from TaskGroup: `../monkeybars.js:899`

Return a Task object, if it exists, based on the `name` passed.

#### Parameters:

- `name` String

  The user defined name

### `getTaskByTid`

(

- `tid`

)

Inherited from TaskGroup: `../monkeybars.js:853`

Return a Task object, if it exists, based on the `tid` passed.

#### Parameters:

- `tid` String

  The id of the task you want

#### Example:

            var parallel = new MonkeyBars.ParallelTask({
                tasks:[task1,task3]
            });

            parallel.getTaskByTid(task1.tid);

### `onCancel`

()

Inherited from Task: `../monkeybars.js:522`

Convenience method called when the task is canceled.

### `onChange`

(

- `state`
- `error`

)

Inherited from Task: `../monkeybars.js:459`

This method is called during the execution lifecycle of the task. It is intentionally left blank and is up to the instance to describe it functionality.

#### Parameters:

- `state` Integer

  The current state of the task

- `error` String

  Message describing error

#### Example:

            var task = new MonkeyBars.Task({
                performTask:function(){
                    this.complete();
                },
                onChange:function(state,error){
                    if(state == MonkeyBars.TaskStates.Completed){
                        alert("complete");
                    }
                }
            });

            task.start();

### `onComplete`

()

Inherited from Task: `../monkeybars.js:511`

Convenience method called when the task completes.

### `onFault`

(

- `error`

)

Inherited from Task: `../monkeybars.js:499`

Convenience method called when the task faults.

#### Parameters:

- `error` String

  Message describing error

### `onStart`

()

Inherited from Task: `../monkeybars.js:488`

Convenience method called when the task starts.

### `onSubTaskCancel`

(

- `task`

)

Inherited from TaskGroup but overwritten in `../monkeybars.js:1225`

Overriden from TaskGroup. As long as the group has not been canceled, when a sub task is canceled it simply moves on to the next task in the queue.

#### Parameters:

- `task` Task

### `onSubTaskComplete`

()

Inherited from TaskGroup but overwritten in `../monkeybars.js:1208`

Overridden from TaskGroup. As long as the group has not been canceled, when a sub task completes it starts the next sibling in the queue.

### `onSubTaskFault`

(

- `error`

)

Inherited from TaskGroup: `../monkeybars.js:754`

Called when a subtask calls its fault method.

#### Parameters:

- `error` String

  Error message.

### `performTask`

(

- `task`

)

Inherited from Task but overwritten in `../monkeybars.js:1243`

Starts the next sub task in the sequence. If overriden you need to call the SequenceTask's prototype `performTask` method.

#### Parameters:

- `task` Task

### `processSubTask`

(

- `task`

)

Inherited from TaskGroup: `../monkeybars.js:787`

Processes a sub task and prepares it for execution. This method overwrites the tasks on change functionality. If you wish to have a sub task that handles its own change functionality then you will need to implement the partner convenience methods.

#### Parameters:

- `task` Task

  Subtask to process

### `removeSubTask`

(

- `task`

)

Inherited from TaskGroup: `../monkeybars.js:834`

Removes a task from its group. Removing the task after it has executed will have no apparent affect as it has already ran.

#### Parameters:

- `task` Task

  The task you wish to remove from the group.

### `start`

()

Inherited from Task: `../monkeybars.js:561`

Kicks off the execution of the task by calling the tasks `performTask` method. This method can only be run once on a task.

### `startNextSubTask`

()

Defined in `../monkeybars.js:1185`

Starts the next task in the queue after its previous sibling has completed.

## Properties

### `currentIndex`

Integer

Inherited from Task: `../monkeybars.js:618`

The index of the subtasks that have completed execution.

Default: 0

### `displayName`

String

Inherited from Task: `../monkeybars.js:323`

Display name for task. Used in logging output.

### `state`

Integer

Inherited from Task: `../monkeybars.js:343`

The current state of the task

Default: 0

### `type`

String

Inherited from Task but overwritten in `../monkeybars.js:1171`

The kind of task