Flash Ads

// in Adaction (Actionscript 3)

clickTag, Interactions and Streaming files 

 

Introduction

Starting with AdAction Adserver  an optional Adobe Flash Component for ActionScript 3 can be used to aid the Flash Developer in making sure ads always works when it is time to go live. Apart from never having to worry about click tags again, it has methods for getting a stream's url and saving interactions.

 

Setup

First of all you need to download the latest AdAction component from http://adaction.se/flash. Before you start using the component it has to be installed. Instructions on how to install components can be found at http://livedocs.adobe.com/flash/9.0/main/00002394.html

To use the component simply drop it on the timeline. The current version number will be displayed next to the AdAction logo. There's no need to place the component outside the movie frame, as it will not be visible at runtime.


 

Download Example and Component

Download Example Flash with Tutorial  (or read it below)

Download  AdAction Flash Component for AcrionScript 3 (1.0.1 / 2009-10-14)

 

 


Tutorial

 

In this tutorial we will be using a Timeline-class called Tutorial, which will include all the setup code.

 

Changing the document class in a Flash File

 

  

Convenience methods

As soon as we have added the AdAction component, we instantly get access to a few convenience methods:

  • AdAction.doClick(): Open the ad's landing page in a new browser window
  • AdAction.doClick(aCustomURL:String): Open a custom landing page in a new browser window
  • AdAction.doClick(aCustomURL:String, aCustomWord:String): Open a custom landing page in a new browser window, and register aCustomWord as the click target for statistics purposes. If aCustomURL is left blank, the click will land on the default landing page as set in AdAction. 
  • AdAction.doInteraction(aKeyword:String): Registers an ad interaction
  • AdAction.initializeInteractionKeywords(...): Registers interaction keywords for later use
  • AdAction.getStreamUrl(aFilename:String): Returns the path to load a stream file from

Handling Ad clicks
Let's start by creating and naming a simple button that we'll use to open the Flash ad's landing page. In this case we want to make the logo clickable.



Naming the landing page button


In our timeline class file we add the following code:

public function Tutorial() {
 setupAd();
}

public function setupAd():void {
 logo.addEventListener(MouseEvent.CLICK, function() {
  AdAction.doClick();
 });
}
It's very important that we bind our event handler to MouseEvent.CLICK. Some browsers block popup windows triggered by other events.

When we run the Flash animation, you should see the following when clicking on the logo:
 
     
[AdAction] Opening default landing page [93, 325]
Error: Adaction.doClick(): No click tag specified!
 at AdAction$/doClick()
 at MethodInfo-38()

 
Since we are not running live we will get an error saying that no click tag was specified. That will change as soon as the ad is running live in AdAction.

 

Multiple URLS

If the ad has more than one landing page (multiple click tags Example: Diffrent travel/product offers) you specify the overridden URL as the first parameter to the doClick()-method:
 
AdAction.doClick("http://www.mysite.com/landing-page-1"); // LP 1
// or...
AdAction.doClick("http://www.mysite.com/landing-page-2"); // LP 2
....wihich will output:
     
[AdAction] Opening custom landing page (http://www.mysite.com/landing-page-1) [102, 326]
[AdAction] Opening custom landing page (http://www.mysite.com/landing-page-2) [102, 326]

 
 

Interactions

 
 
An interaction is an event that do not open a window, but the client still wants statistics on. Before registering an interaction we must initialize all the keywords we are going to use in the ad by calling the method initializeInteractionKeywords(...). In this example we'd like to register an interaction when the user clicks on the first or the second tab.

Let's modify our setupAd()-method by adding the following:
AdAction.initializeInteractionKeywords("aboutTab", "movieTab");
 
This informs the ad that the interaction keywords tab1 and tab2 may be used.

When we want to inform AdAction that an event has occurred we call doInteraction() with the keyword name as the only parameter. The tutorial ad has two tabs that registers an interaction when clicked on:
aboutTab.addEventListener(MouseEvent.MOUSE_UP, function() {
 AdAction.doInteraction("aboutTab");
});
movieTab.addEventListener(MouseEvent.MOUSE_UP, function() {
 AdAction.doInteraction("movieTab");
});
 

Streaming Files

  
Streaming files in AdAction has no predetermined URL, and you can't assume that the video will be available. Some clients buy a fixed amount of video streams, and the ad should adapt accordingly. When running the ad locally it's assumed that the flv or swf files are stored in the same folder as the main flash file. The method getStreamUrl(filename:String) returns the right URL for the passed in filename if the streaming file is accessable. If it's not, null will be returned.

In the example ad we load a streaming file called stream.flv:
 
private function startVideo(e:TabEvent):void {
 _video.visible = true;
 
 // If the stream hasn't yet been loaded,
 // load it now.
 if (!_stream) {
  var url = AdAction.getStreamUrl("stream.flv");
  
  // Make sure we have a valid URL.
  if (url) {
   _stream = new NetStream(_connection);
   _stream.client = {};
   _stream.play(url);
   _video.attachNetStream(_stream);
  }
 } else {
  _stream.seek(0);
  _stream.resume();
 }
}