How to: queuing actions

Sometimes you want to set a list of actions for InlineManualPlayer to do. But you can't be sure whether this list will be set before or after the Player has been created and initialized. In these cases, you can use the queuing. It looks like this:

var my_topics = {
  some_topic: {
    title: 'Some topic'
    steps: [{title: 'First step'}, {title: 'Second step'}]
  }
}
 
var inline_manual_player = inline_manual_player || []; 
inline_manual_player.push(['setTopics', my_topics]);
inline_manual_player.push(['activateTopic', 'some_topic']);

This will set a topic in the Player instance and then activate it. If this code is inserted before the Player code, it will be executed immediately after the Player's instance has been created.

It works like this:

var inline_manual_player = inline_manual_player || [];

This line checks whether Player instance in variable inline_manual_player already exists. If not, it creates a simple array that will contain the queue.

inline_manual_player.push(['someAction', 'first argument', 'second argument']);

This adds an item to the queue. If the Player instance already exists, it will be executed immediately. The push()method should always receive only one argument of the type Array. First item in the array should be the name of the method to be called. All the other items in the array will be used as arguments for this method.

Was this article helpful?