Home > OS >  Adobe Air, not able to open html content in new window
Adobe Air, not able to open html content in new window

Time:09-17

I am not able to solve this issue despite trying very hard, hence posting it here.

As the title says, I have an Adobe air desktop app and when I click a button I want to display one html content from a remote server.

I have tried two approaches, namely HtmlLoader and StageWebView. These are opening a new Window, but not displaying the html content.

My sample html file -

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>

Action script code -

var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
windowOptions.type = NativeWindowType.NORMAL;
var newWindow:NativeWindow = new NativeWindow(windowOptions);
newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
newWindow.stage.align = StageAlign.TOP_LEFT;
newWindow.activate();

var htmlLoader:HTMLLoader = new HTMLLoader();
htmlLoader.width = newWindow.stage.stageWidth;
htmlLoader.height  = newWindow.stage.stageHeight;
var request:URLRequest = new URLRequest(url);
htmlLoader.load(request);
newWindow.stage.addChild(htmlLoader);

But the htmlLoader is not displaying the content. Even I tried with asynchronous method -

htmlLoader.addEventListener(Event.COMPLETE, onComplete);

but even then no content!

I tried with StageWebView, as documented here, but even then the same problem!

var webView:StageWebView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.loadURL(url);

I went through all the examples as mentioned here, don't know whether I should try any other alternative approach.

How can I fix this issue?

Thanks.

CodePudding user response:

I recently built an AIR desktop app for MacOS and Windows and came across lots of issues with StageWebView. I ended up using a ANE.

Tuarua Webview ANE

Regarding your code above:

  • The url variable is not being set.

  • Set width and height as hard coded integers to ensure width or height is not being set to 0.

  • Initially test with a trusted url like www.google.com to rule out issues with your own server.

  • Related