screenad.shared Singleton
Shared connection
The shared connection allows ads that come from the same campaign to communicate with each other.
The mechanism works as follows:
- Setup up a callback function in all the ad elements (banners and layers) that should receive a message.
- Call this function from one of the ad elements.
- `Shared functions` can receive any basic variable type as a parameter. (number, boolean, string, array, object)
- Communication between Flash and HTML5 ad elements is possible.
- 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