AS3 XML With javascript popup bypass

I posted this also in AS3 because this there is javascript and AS3 working together here.

Hi Guys,

I’m busy with making a XML banner in AS3. It worked so far with the following code:


[LEFT]var xmlLoader:URLLoader = new URLLoader(); 
var xmlData:XML = new XML(); 
xmlLoader.addEventListener(Event.COMPLETE, LoadXML); 
xmlLoader.load(new URLRequest("private")); 
function LoadXML(e:Event):void { 
xmlData = new XML(e.target.data); 
Parseacco(xmlData); 
} 
function Parseacco(accommodatie:XML):void { 
var lengte = accommodatie.product.length();
lengte --;
var i = (Math.round(Math.random() * lengte) );
productnaam1_mc.productnaam.text = (accommodatie.product.name.text()*) ; 
prijs1_mc.prijs.text = ("€ " + accommodatie.product.price.text()* + ",-");
gebied1_mc.gebied.text = (accommodatie.product.additional*.field[2].(@name) + "?");
var link = (accommodatie.product.productURL.text() *);
// Clicktag AS3
var exclude = "private";
var myPattern:RegExp = new RegExp(exclude,"gi");
var str:String = link;
var newLink = (str.replace(myPattern, ""));
var paramList:Object = this.root.loaderInfo.parameters;
myButton.addEventListener(MouseEvent.CLICK, openURL);
function openURL(evtObj:MouseEvent):void {
var request:URLRequest = new URLRequest(link);
navigateToURL(request, "_blank");
}[/LEFT]
 
 
[LEFT]} 
[/LEFT]

Problem with this, that the navigateToURL gets blocked by most new browsers and gives a popup alert.

I have used a workaround to bypass the popupblocker with javascript. I didn’t used the window.open method but used forms.

the code looks like this:


[LEFT]import flash.external.ExternalInterface;
var xmlLoader:URLLoader = new URLLoader(); 
var xmlData:XML = new XML(); 
xmlLoader.addEventListener(Event.COMPLETE, LoadXML); 
xmlLoader.load(new URLRequest("PRIVATE")); [/LEFT] 
[LEFT]function LoadXML(e:Event):void { 
xmlData = new XML(e.target.data); 
Parseacco(xmlData); 
} 
//XML ophaal functie | Retrieve XML
function Parseacco(accommodatie:XML):void { 
//Random genarator
var lengte = accommodatie.product.length();
lengte --;
var i = (Math.round(Math.random() * lengte) );
//Informatie uit XML in mc schrijven | Retrieve XML info
productnaam1_mc.productnaam.text = (accommodatie.product.name.text()*) ; 
prijs1_mc.prijs.text = ("€ " + accommodatie.product.price.text()* + ",-");
gebied1_mc.gebied.text = (accommodatie.product.additional*.field[2].(@name) + "?");
var link:String = (accommodatie.product.productURL.text() *);
//Link wijzigen voor clickTag | Edit link for clickTag 
var exclude:String = "PRIVATE";
var myPattern:RegExp = new RegExp(exclude,"gi");
var str:String = link;
var newLink:String = (str.replace(myPattern, "")); 
//clickTag Ophalen | Retrieve clickTag
var paramList:Object = this.root.loaderInfo.parameters;
//Link samenvoegen met clickTag | Merge static link with XML link
trace(newLink);
var totalLink:String = paramList["clickTag"]+newLink;[/LEFT]
 
[LEFT]//Popup bypass Javascript 
myButton.addEventListener(MouseEvent.CLICK, openURL);
function openURL(evtObj:MouseEvent):void { ExternalInterface.call('(function (){ var f = document.createElement("form");document.body.appendChild(f);f.style.display="none";f.setAttribute("target","_blank");f.setAttribute("method","GET");f.setAttribute("action","'+totalLink+'");f.submit(); })()');}[/LEFT]
 
[LEFT]} 
[/LEFT]

And it worked! It bypassed all the browsers popup blockers, but it brought in some new problems.

Every time the .swf loops. The addeventlistener adds a listener. So if the .swf loops 5 times it wil open 5 windows when i will click it. I’ve tried to use removeeventlistener but with no succes so far. In the code without the popup bypass this problem didn’t occured. Probally due the new URLRequest. But I don’t know how to use this in the javascript.

The other problem is the string of the link. For some reason javascript deletes parts of the link when there is an questionmark in it. Example:

if the link is [COLOR=#003366]www.google.nl/test?=information[/COLOR]
the link what will open is: [COLOR=#003366]www.google.nl/test[/COLOR]

I tried to google but didn’t helped me. Anyone an idea?

Thanks in advance!!!