views:

54

answers:

2

Hi

I'm writing a simple html page creator that will generate html code on customized settings. Now i want to add a "Demo" button that will generate a html page on the fly for the user to see the end result.

Is there any way to generate it in an online application?

Thanks

+1  A: 

You could do something like that:

var url:String = "http://servlet.url";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.html = source.of.your.html;
request.data = variables;
navigateToURL(request, "_blank");

So you basically navigate to some servlet that you have on your server, sending it html that you've created in your Flex app as a POST parameter and opening received responce in the new window/tab. Servlet should send received html back allowing preview of created html to the end user.

2DH
Thanks for the reply, I was actually looking for a on the fly situation that doesn require a serverside operation. I know it can be done using AIR but i was looking for some browser-based solution. Anyhow it is clear now there is no other solution but to involve server here. Thanks again
Max
+1  A: 

Actually, you don't need to use the server. You can use javascript: urls within Flash to achieve what you want, like so:

var request:URLRequest = new URLRequest("javascript:var w=window.open('', 'FlashGeneratedHTML', 'width=400, height=400'); w.document.write('<html><head></head><body>hello</body></html>');" );
navigateToURL(request, "_self");

All you need to do is replace the HTML code in the document.write() part of the JavaScript code with your own code.

geckojsc
Great, this is what i was actually looking for :) Thanks a lot
Max