Search code examples
javascriptapache-flexairflash-builder

Print HTML object content in Adobe Flex


I used HTML browser object in the Flex Air project, but there's a problem with printing in Flex HTML browser.

  1. JavaScript print function does not work
  2. Does not open download windows

How can I fix this?


Solution

  • A solution I used is to change some JavaScript functions with my own, so when a save dialog did not worked I investigated and the thing is that in a normal browser a new tab/window was opening with the URL of the download file, so I changed the open function

    function newOpen(url, name, features) {
    
    }
    
    window.open=new open;
    

    The above code was injected in the HTML page and run when the scripts was loaded. You should be able to do it from AS3 as well, you get the window object like this

    var window:*=myHTMLComponent.htmlLoader.window;
    

    Then as above you change the open function with a newOpen function and implement in the new function the things you need.

    About printing it seems that you will have to use the Flash printing and print the HTML component, I found a tutorial for this. I think this printing of HTML is not recommended (it worked for me with graphs and other components, but it is a lot of work to get it to look right) so maybe saving the HTML to disk and then printing the file using a native browser or program will work better.