Reputation: 1475
I've got an AIR app that is loading mx:HTML
s. I would like to block the ads that show in them just like Adblock Plus for Firefox does (see http://adblockplus.org/en/). I subscribe to the Easylist USA filter.
var req:URLRequest = new URLRequest("http://www.google.com");
thisHtmlWindow.open();
thisHtmlWindow.htmlContent.htmlLoader.load(req);
I don't know where to begin to interrupt the HTML GET-ting process in actionscript. This is where I suspect I can add the HTTP filter. It'd be nice to subscribe to the filter and periodically download it/update it to make sure the major ad networks are blocked.
Upvotes: 1
Views: 972
Reputation: 6059
Good question. I would start by intercepting the result that comes back from the request, manipulating the HTML, then load it into the HTMLLoader. You do this by initially retrieving your content using a URLLoader rather than the HTMLLoader. After you get and manipulate your content, set it into your HTMLLoader using HTMLLoader.loadString. Hope that helps.
EDIT: Here's a little code for you.
var urlLoader:URLLoader = new URLLoader();
public function loadUrl(url:String):void {
var request:URLRequest = new URLRequest(url);
_urlLoader.addEventListener(Event.COMPLETE, onHtmlLoaded);
_urlLoader.load(request);
}
private function onHtmlLoaded(event:Event):void {
_urlLoader.removeEventListener(Event.COMPLETE, onHtmlLoaded);
// This is where you can mess with the data before setting it
var content:String = _urlLoader.data as String;
myHtmlComponent.htmlLoader.loadString(content);
}
Upvotes: 1