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:
setupAd();
}
public function setupAd():void {
logo.addEventListener(MouseEvent.CLICK, function() {
AdAction.doClick();
});
}
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() |
||
Multiple URLS
// or...
AdAction.doClick("http://www.mysite.com/landing-page-2"); // LP 2
| [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
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:
AdAction.doInteraction("aboutTab");
});
movieTab.addEventListener(MouseEvent.MOUSE_UP, function() {
AdAction.doInteraction("movieTab");
});
Streaming Files
In the example ad we load a streaming file called stream.flv:
_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();
}
}