Requirements
Flash version >= 9 and ActionScript 3.0
Description
The Video Ads Module provides a way to show video ads (linear and non-linear) on any flash video player with source code access.
The module uses it's own video player engine.
How to use
- Import the VideoAdsDefs & VideoAdsEvent files
-
Load the Video Ads Module. For example:
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadVideoAdsModuleComplete);
var url:URLRequest = new URLRequest("http://www.vidata.gr/files/v_ads_v(x).swf");
ldr.load(url);
-
Add the loaded movie as a child to any of your DisplayObject containers. The module must be on the front of all the other clips to capture the click events. For example:
function onLoadVideoAdsModuleComplete(evt:Event) {
var li:LoaderInfo = evt.target as LoaderInfo;
this.vadsModule = li.content;
this.someClip.addChild(this.vadsModule);
}
-
Resize the module to your desired size: vadsModule.events.onStageResized(width, height);
(Normally the size is the video area size)
-
Setup the event handlers. For a list of events see the Events section.
-
Initialize the module by calling vadsModule.adsInit(url) where url is the video ads xml template. Wait for the VideoAdsDefs.VADS_EVENT_LOADED event to be fired.
-
Call the vadsModule.adsPlayAd(position) to check for video ads.
Functions
-
vadsModule.adsInit(url):void
Initializes the module with the specified (url) template.
-
vadsModule.adsPlayAd(position):Boolean
Checks for video ad at the specified position and if one found it starts playing. Positions are:
-
VideoAdsDefs.CHECK_VIDEO_START
Before the video starts playing
-
VideoAdsDefs.CHECK_VIDEO_MID
At the middle of the video
-
VideoAdsDefs.CHECK_VIDEO_END
When the video has ended playing
-
VideoAdsDefs.CHECK_NON_LINEAR
When the video starts playing. This is for video ads that will play along with the video.
Notifications
Notifications are the way to notify the Video Ads Module that something happened and it must do something about it.
For example if the audio volume change on the player then the module must be notified to change it's volume too.
The available notifications are:
-
onStageResized(width:Number, height:Number):void
Call this when the module first loaded and on any resize of the player.
-
onVolumeChanged(volume:Number):void
Call this when the audio volume changed.
-
onVideoEnded():void
Call this when the video has ended playing.
-
onVideoClicked():Boolean
Call this when your video player prevents the module to capture the click events and the user clicked on the video ads area. If the function returns false you can continue with the click event, otherwise you must do nothing. Normally the module must be at the top position in the z-order of the clips.
-
onFullscreen():void
Call this when the player enters the full screen mode.
Those functions are available through vadsModule.events object
Events
To setup an event handler for Video Ads Module you must use the vadsModule.events.addEventListener function.
For example: vadsModule.events.addEventListener(VideoAdsDefs.VADS_EVENT_LOADED, this.onAdsPluginReady);
The events are:
-
VideoAdsDefs.VADS_EVENT_LOADED
Fired when the video ads template xml was loaded after a call to vadsModule.adsInit
-
VideoAdsDefs.VADS_EVENT_LINEAR_AD_READY
Fired when the video ad is ready to start playing. The Event parameter is a VideoAdsEvent Class object. Called only for linear video ads.
-
VideoAdsDefs.VADS_EVENT_LINEAR_AD_STARTED
Fired when the video ad starts playing. The Event parameter is a VideoAdsEvent Class object. Called only for linear video ads.
-
VideoAdsDefs.VADS_EVENT_LINEAR_AD_ENDED
Fired when the video ad finished playing. The Event parameter is a VideoAdsEvent Class object. Called only for linear video ads.
Objects
VideoAdsEvent
The main event object. Has only one property: object which has the property placement.
placement property can be:
-
VideoAdsDefs.VIDEO_AD_PLACEMENT_PRE
Before the video starts
-
VideoAdsDefs.VIDEO_AD_PLACEMENT_MID
At the middle of the video
-
VideoAdsDefs.VIDEO_AD_PLACEMENT_POST
After the video finishes playing
Usage example:
vadsModule.events.addEventListener(VideoAdsDefs.VADS_EVENT_LINEAR_AD_READY, onAdsModuleAdReady);
function onAdsModuleAdReady(evt:VideoAdsEvent) {
if (evt.object.placement == VideoAdsDefs.VIDEO_AD_PLACEMENT_MID) {
// do something
}
}