OpenX Loader ActionScript 3 Class for Adobe AIR

Following my article on loading OpenX ads in Adobe AIR applications, I’ve written a very simple class to make it a little easier. This should be able to load in both image and HTML/text based banners with no problem.

This class will NOT run in the regular Flash Player. It requires Adobe AIR to function. Also, banner clicks from the Debug Launcher will NOT redirect properly (you’ll get a 404), but once the AIR app is compiled and installed links will work as they should and will be included in your OpenX stats.

The Constructor Method

Extends the Sprite class.

OpenxLoader(w:Number, h:Number, url:String)

  • w: width of the HTMLLoader
  • h: height of the HTMLLoader
  • url: URL to load in the HTMLLoader (the code of this page should have your OpenX invocation code with all applicable zones)

Public Properties

  • html: Public reference to the HTMLLoader instance
  • height: Height of the HTMLLoader instance
  • width: Width of the HTMLLoader instance
  • url: URL to load in the HTMLLoader instance (automatically loads the new URL when changed)

Public Methods

  • refresh: Reloads the content in the HTMLLoader instance

Basic Example


//Import the class
import us.studiochris.openx.OpenxLoader;

//Create a new instance of the class
var ads:OpenxLoader = new OpenxLoader(125, 125, "http://domain.com/open-x-ad-page.html");

//Add the OpenxLoader to the Stage
addChild(ads);Code language: ActionScript (actionscript)

Auto-refreshing Example


//Import the class
import us.studiochris.openx.OpenxLoader;

//Create a new instance of the class
var ads:OpenxLoader = new OpenxLoader(125, 125, "http://domain.com/open-x-ad-page.html");

//Add the OpenxLoader to the Stage
addChild(ads);

//Create a new Timer to control the refresh rate
var t:Timer = new Timer(60000,1); // 1 minute refresh rate in milliseconds and we want to run it once

//Start the Timer
t.start();

//Add an Event Listener to the Timer and define the reloadAds function
t.addEventListener(TimerEvent.TIMER, reloadAds);

function reloadAds(e:TimerEvent):void
{
	//Call the refresh method of the OpenxLoader (has the effect of a rotating banner)
	ads.refresh();

	t.start(); //start the timer again so it'll call this function again in one minute
}Code language: ActionScript (actionscript)

Flex 4 Framework Basic Example


<?xml version="1.0" encoding="utf-8"?>
<s:Application name="Flex4_AdLoader_Example" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" initialize="init();">
		<fx:Script>
			<![CDATA[
				import us.studiochris.openx.OpenxLoader;
				
				private function init():void
				{
					var adloader:OpenxLoader = new OpenxLoader(600,600,"http://www.google.com");
					box.addChild(adloader);
				}
			]]>
		</fx:Script>
	<s:SpriteVisualElement id="box" />
</s:Application>
Code language: HTML, XML (xml)