Hi,
I'm trying to get Flex and OpenX to work together.
OpenX is returning XML. I've got two Flex classes that clean-up the XML and place the ads on my site (thank you Daryl Bowden). Unfortunately, I get Error #1090: XML parser failure, when I test it. And I can't figure out why.
The first class is:
package com.darylbowden.ads
{
import mx.controls.Alert;
public class Ad extends Object {
private var _clickURL:String;
private var _mediaSource:String;
private var _target:String;
private var _flash:Boolean;
public function Ad(xhtml:XML, flash:Boolean = false) {
super();
_flash = flash;
_parse(xhtml);
}
private function _parse(xhtml:XML):void {
if(!_flash) {
_clickURL = [email protected]();
_mediaSource = [email protected]();
}
else if (_flash) {
_mediaSource = [email protected]();
var clickIndex:uint = _mediaSource.indexOf('clickTAG=', 0);
_clickURL = _mediaSource.substring( clickIndex+9, _mediaSource.length);
}
}
public function get clickURL():String {
return _clickURL;
}
public function get mediaSource():String {
return _mediaSource;
}
public function get target():String {
return _target;
}
}
}
The second class is:
package com.darylbowden.ads
{
import flash.external.ExternalInterface;
import mx.controls.Alert;
public class OpenAds {
private static var externalCallback:String = "callOpenAds";
private static var retries:uint = 10;
public function OpenAds(){
}
public function getAdReturn():Ad {
var xmlReturn:XML;
if(ExternalInterface.available) {
var adReturn:String = ExternalInterface.call(externalCallback);
try
{
adReturn = adReturn.replace("//]]>->","//]]>->\n");
var infoTagsIndex:int = adReturn.indexOf('<script type="text/javascript" src=""', 0);
adReturn = adReturn.substring(infoTagsIndex, adReturn.length);
var wasFlash:Boolean = false;
if(adReturn.search("<embed") == -1) {
adReturn = adReturn.replace('></a>', '></img></a>');
adReturn = adReturn.replace('></div>', '></img></div>');
}
else {
adReturn = adReturn.replace('></div>\n<script','></embed></div>\n<script');
adReturn = adReturn.replace('></div>\n<noscript','></img></div>\n<noscript');
wasFlash = true;
}
adReturn = '<adXMLReturn>' + adReturn + '</adXMLReturn>';
xmlReturn = new XML(adReturn);
var ad:Ad;
if(wasFlash){
ad = new Ad(xmlReturn, true);
}
else {
ad = new Ad(xmlReturn);
}
}
catch(error:Error){
Alert.show(error.message + 'stacktrace: ' + error.getStackTrace(), "Error");
}
}
else {
Alert.show("Javascript must be enabled to view this page properly.", "Javascript Not Detected");
xmlReturn = new XML('<root>xml</root>');
}
return ad;
}
}
}
This is the what OpenX returns:
var OX_28140bee = '';
OX_28140bee += "<"+"a href=\'http://www.dcscore.com/openx/www/delivery/ck.php?oaparams=2__bannerid=1__zoneid=4__cb=42492045be__oadest=http%3A%2F%2Fwww.joeblow.com\' target=\'_blank\'><"+"img src=\'http://www.joeblow.com/openx/www/delivery/ai.php?filename=mybanner.png&contenttype=png\' width=\'468\' height=\'60\' alt=\'\' title=\'\' border=\'0\' /><"+"/a><"+"div id=\'beacon_42492045be\' style=\'position: absolute; left: 0px; top: 0px; visibility: hidden;\'><"+"img src=\'http://www.joeblow.com/openx/www/delivery/lg.php?bannerid=1&amp;campaignid=1&amp;zoneid=4&amp;loc=http%3A%2F%2Fwww.dcscore.com%2F&amp;cb=42492045be\' width=\'0\' height=\'0\' alt=\'\' style=\'width: 0px; height: 0px;\' /><"+"/div>\n";
document.write(OX_28140bee);
Unfortunately, I can't figure out what the error is. Any suggestions? I'm ready for a lobotomy.
Thank you.
-Laxmidi
/////////////////////
As Antti suggested, I traced adReturn. Please see below:
<script type="text/javascript"><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://www.dcscore.com/openx/www/delivery/ajs.php':'http://www.dcscore.com/openx/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=4");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><script type="text/javascript" src="http://www.dcscore.com/openx/www/delivery/ajs.php?zoneid=4&amp;cb=46672151726&amp;charset=UTF-8&amp;loc=http%3A//www.dcscore.com/"></script><a href="http://www.dcscore.com/openx/www/delivery/ck.php?oaparams=2__bannerid=1__zoneid=4__cb=5f5d8fcb97__oadest=http%3A%2F%2Fwww.dcscore.com" target="_blank"><img src="http://www.dcscore.com/openx/www/delivery/ai.php?filename=mybanner.png&amp;contenttype=png" width="468" height="60" alt="" title="" border="0"></a><div id="beacon_5f5d8fcb97" style="position: absolute; left: 0px; top: 0px; visibility: hidden;"><img src="http://www.dcscore.com/openx/www/delivery/lg.php?bannerid=1&amp;campaignid=1&amp;zoneid=4&amp;loc=http%3A%2F%2Fwww.dcscore.com%2F&amp;cb=5f5d8fcb97" width="0" height="0" alt="" style="width: 0px; height: 0px;"></div>
<noscript></noscript>
I still don't see the error. Hopefully someone will see the problem.
Thank you. -Laxmidi