API Docs for: 6.0.1
Show:

Action Class

Action

Instantiation

  • scrawl.makeAction()

Purpose

  • Defines a reversible function which can subscribe to a ticker so that it gets invoked at a particular moment after the ticker starts to run

Actions only really make sense when they are associated with a Ticker object. They have no duration as such (unless their action/revert functions include asynchronous activities, in which case - you're on your own!). The action() function should define a set of near-instant actions; the revert() function should mirror the action, to allow the Action object to be reversible.

Action and revert functions are not expected to take any arguments - they are expected to act on the objects assigned to their targets Array

To access the Action functions directly, assign it to a variable, or call it from the library:

  • scrawl.tween[ACTIONNAME].action()
  • scrawl.tween[ACTIONNAME].revert()

Access

  • scrawl.tween.ACTIONNAME - for the Action object

Action functions

  • An Action can be invoked by calling its action() function.
  • An Action can be reversed by calling its revert() function.
  • An Action can be deleted by calling the kill() function on it.

Constructor

Action

(
  • [items]
)

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Methods

addToTargets

(
  • items
)
chainable

Add Objects to targets attribute - assumes that the supplied Array will augment any existing targets array

Parameters:

  • items Array

    Array of Objects and/or Strings, can also be single Object or string

Returns:

this

addToTicker

(
  • item
)
chainable

Add action to given ticker

If action is already subscribed to a different ticker, the function will automatically unsubscribe from that ticker before subscribing to the new ticker

Parameters:

  • item String

    TICKERNAME to which this Action will subscribe

Returns:

this

calculateEffectiveTime

(
  • [item]
)
private chainable

Get the effective (millisecond number) time when action will trigger

Parameters:

  • [item] String optional

    new time value; defaults to this.time

Returns:

this

clone

(
  • Object
)
chainable

Inherited from Base but overwritten in source\scrawlAnimation.js:2094

Create a clone of this Action

Note: strongly advise every call to this function includes newly created anonymous functions for the action and revert attributes in the argument object - Scrawl's clone functionality does not clone function attributes!

Parameters:

  • Object Object

    containing key:value attributes

Returns:

a new copy of the Action object

get

(
  • item
)

Retrieve an attribute value. If the attribute value has not been set, then the default value for that attribute will be returned.

Parameters:

  • item String

    Attribute key

Returns:

Attribute value

Example:

var box = scrawl.makeBlock({
    width: 50,
    });
box.get('width');               //returns 50
box.get('height');              //returns 0
box.get('favouriteAnimal');     //returns undefined

getEndTime

() private

retrieve the completion time for the action

Returns:

Number

kill

()

Remove this Action from the scrawl library

Returns:

Always true

numberConvert

(
  • val
  • dim
)
private

Stamp helper function - convert string percentage values to numerical values

Parameters:

  • val String

    coordinate String

  • dim Number

    dimension value

Returns:

Number - value

parse

()

Turn the object into a JSON String

Returns:

object of object's currently set attributes

removeFromTargets

(
  • items
)
chainable

Remove Objects from targets attribute - will not remove an object with no name and/or type attributes

Parameters:

  • items Array

    Array of Objects and/or Strings, can also be single Object or string

Returns:

this

removeFromTicker

(
  • item
)
chainable

Remove action from given ticker

Parameters:

  • item String

    TICKERNAME to which this Action will unsubscribe

Returns:

this

set

(
  • Object
)
chainable

Inherited from Base but overwritten in source\scrawlAnimation.js:1926

Set attributes

Parameters:

  • Object Object

    containing key:value attributes

Returns:

this

setTargets

(
  • items
)
private chainable

Set targets attribute - assumes that the supplied Array will replace, not amend, any existing targets array

Parameters:

  • items Array

    Array of Objects and/or Strings, can also be single Object or string

Returns:

this

update

(
  • items
)
private

Investigate the data supplied by the ticker and, if necessary, invoke the action or revert functions, as appropriate

The object passed by the ticker has the following attributes:

  • tick - milliseconds since ticker started its run
  • reverseTick - milliseconds before ticker reaches the end of its run
  • willLoop - boolean indicating whether ticker is about to restart
  • next - boolean indicating whether this is the ticker's last update

Parameters:

  • items Object

    Object sent by ticker

Returns:

always true

updateTargets

(
  • items
)
chainable

Update target attributes

Parameters:

  • items Object
    • containing key:value attributes to be forwarded to target set() functions

Returns:

this

Properties

action

Function

Action function

Default: function(){}

comment

String

Comment, for accessibility

Default: ''

name

String

Unique identifier for each object; default: computer-generated String based on Object's type

order

Number

Sort order - for Actions that share the same time value on a given Ticker. Without a sort order, there will be no guarantee which actions with the same time value will be performed first

Default: 0

reversed

Boolean

Reversed - when true, the action is using reverseTick value

Default: false

reverseOnCycleEnd

Boolean

Reversable flag - when true, the action will alternate the tick and reverseTick values as the ticker cycles

Default: false

revert

Function

Revert function - should reverse the actions of the .action function

Default: function(){}

targets

Array

Array of Objects on which this Action will perform its action and revert functions; if the array includes Strings, the constructor, set and clone functions will search for the Objects in the Scrawl library, checking sections (if they currently exist) in the following order:

  • entity, cell, pad, stack, element, point, group, design, animation, tween, anim, filter, image, force, spring, physics

This attribute can also accept a single Object or String as its value in the

Default: []

ticker

String

Ticker name If an Action object is associated with a ticker, it will fire (or revert) at the appropriate point in the course of the ticker's run.

Default: ''

time

Number

Time - point (in milliseconds) following the start of the Action's ticker when the action function will trigger

Default: 0

timestamp

String

Creation timestamp

Default: ''

title

String

Title, for accessibility

Default: ''

type

String final

Inherited from Base but overwritten in source\scrawlAnimation.js:1716

Default: 'Action'