How to download HTML-linked files within AIR application?

0

I created an application with Adobe AIR and I threw inside it the HTML component that will open my desired page. The problem I'm having is that within my HTML page there are some file download functions, but these do not work because they are inside the AIR application.

Any idea what I can do to be able to download these files from the HTML page that is inside the AIR application?

With the code below the page opens the download link, but it is blank, a popup is opened but the file is not downloaded and I can not even see it.

htmlContent.location = "minha url";
var htmlhost:HTMLHost = new HTMLHost(true);         
htmlContent.htmlLoader.htmlHost = htmlhost; 
    
asked by anonymous 09.12.2014 / 11:50

1 answer

2

I found the solution to my problem in this tutorial , I hope serve someone.

The solution is to create, by code, a handler onclick for all page links after it has loaded, and use navigateToURL within that handler to open the link in the browser.

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HTML id="htmlComp" width="100%" height="100%" location="http://www.rediff.com" complete="addEventListenersToLinks(event)"  />

 <mx:Script>
  <![CDATA[

   private function addEventListenersToLinks(e:Event):void
   {
    var dom:Object = e.currentTarget.domWindow.document;
    var links:Object = dom.getElementsByTagName("a");

    for(var i:Number = 0; i < links.length; i++)
    {
     if(links[i].target.toLowerCase() == "_blank" || links[i].target.toLowerCase() == "_new")
      links[i].onclick = linkClickHandler;
    }
   }

   private function linkClickHandler(o:Object):void
   {
    navigateToURL(new URLRequest(o.currentTarget.href),"blank");
   }
  ]]>
 </mx:Script>
</mx:WindowedApplication>
    
10.12.2014 / 19:57