Reputation: 787
I have been stuck trying to figure this out...
I have a Flex (Flash) App, and I am called a JavaScript function and passing in data:
if (ExternalInterface.available)
ExternalInterface.call("jsFunctionToCalled", passingSomeData);
In my index.template.html file, I have created the JS function:
<script type="text/javascript">
function jsFunctionToCalled(value) {
window.alert(value);
}
</script>
When I click a Button component in Flex, that JS alert window pops up. That works fine; However, I would like to open up a browser window, where I can access the "File/Print" option. I need to open this new browser window and parse the data from the value object. The value object is a String of HTML formatted data. So I need to display that data on the new popup window. I was thinking maybe I need to do something like this, which someone posted somewhere, but nothing pops up. I also tried window.opener and nothing pops up. If I provide a URL, it opens the URL fine, but I do not want to open a URL, I want to open a new window that I can print, and populate the window with the HTML data.
<script>
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("This is 'myWindow'!");
myWindow.focus();
myWindow.opener.document.write("<p>This is the source window!</p>");
}
</script>
Any help will be greatly appreciated. I am trying to figure a way to be able to print, without saving the file first (CRAPPY FLASH), and I do not have a web server to save my file to, in order to avoid saving the file first.
Thanks
Upvotes: 1
Views: 3334
Reputation: 16
The above changes works perfectly....
One addition - if you want to automatically close the new window after printing add the w.close() in the script
<script type="text/javascript">
function onPrintRequest(value) {
var w = window.open("about:blank");
w.document.write(value);
w.document.close();
w.focus();
w.print();
w.close();
}
</script>
Upvotes: 0
Reputation: 787
I figured this out and thought I would share it for anyone else experiencing this problem:
In my Flex Code:
if (ExternalInterface.available)
{
try
{
ExternalInterface.call("onPrintRequest", dataToPass);
}
catch (error:SecurityError)
{
Alert.show("Printing Security Error");
}
catch (error:Error)
{
Alert.show("Printing Error");
}
}
else
{
Alert.show("Printing currently unavailable");
}
In my index.template.html I added this JS method:
<script type="text/javascript">
function onPrintRequest(value) {
var w = window.open("about:blank");
w.document.write(value);
w.document.close();
w.focus();
w.print();
}
</script>
Works like a charm!!!
Upvotes: 1