screenad.shared Singleton

Methods 1

Shared connection

The shared connection allows ads that come from the same campaign to communicate with each other.

The mechanism works as follows:

  1. Setup up a callback function in all the ad elements (banners and layers) that should receive a message.
  2. Call this function from one of the ad elements.
  3. `Shared functions` can receive any basic variable type as a parameter. (number, boolean, string, array, object)
  4. Communication between Flash and HTML5 ad elements is possible.
  5. If you call a shared function before the receiving ad element is properly loaded, the message will not be delivered.

Sample setup

Code in listening ad element(s):

// Define a callback function that starts animation when called via shared connection.
screenad.shared.startAnimation = function(animationColor) {
  if (animationColor === 'red') {
    animRed.start();
  }
  else {
    animGreen.start();
  }
};

Code in sending ad element:

// Trigger the callback function `startAnimation` on listening ad elements.
screenad.shared.callMethod("startAnimation", 'red');
Method Details
callMethod(method, param)

This function makes a call to all ad elements that reside on the same webpage, given that they are from the same campaign.

This function makes a call to all ad elements that reside on the same webpage, given that they are from the same campaign.
If an ad element has a callback function with the same name defined in the parameter `method`, this function will be executed.

Simple example:

// Code in banner
screenad.shared.callMethod("startAnimation");

// Code in layer
screenad.shared.startAnimation = function() {
    anim.start();
};
Parameters:
{String} method
{Object|String|Number} param