how to work with air 3.2 and HTMLLoader?

2019-06-14 19:41发布

问题:

i use this code to view my web page .... it is work with air 3.2 for desktop ... how to make it work with air 3.2 for android ? .... it does not loading anything , only white screen !

package {
import flash.display.Sprite;
import flash.html.HTMLLoader;
import flash.net.URLRequest;

public class HTMLLoaderExample extends Sprite
{
    public function HTMLLoaderExample()
    {
        var html:HTMLLoader = new HTMLLoader();
        var urlReq:URLRequest = new URLRequest("http://www.doomanco.com/");
        html.width = stage.stageWidth;
        html.height = stage.stageHeight;
        html.load(urlReq); 
        addChild(html);
        html.x = 0;
        html.y = 0;
        }
    }
 }

回答1:

As Adobe said about HTMLLoader: " AIR profile support: This feature is supported on all desktop operating systems, but is not supported on mobile devices or on AIR for TV devices. You can test for support at run time using the HTMLLoader.isSupported property. See AIR Profile Support for more information regarding API support across multiple profiles. ", I think that's not supported for your android device, you ca verify that using HTMLLoader.isSupported property. For more details you can take a look here : Adobe.com : HTMLLoader and here : Adobe.com : Device profiles for AIR.



回答2:

thanks dude @DodgerThud & @akmozo ..... it is done with this:

package  {
import flash.display.MovieClip;
import flash.media.StageWebView;
import flash.geom.Rectangle;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.desktop.NativeApplication;
import flash.display.Stage; 
import flash.display.StageAlign; 
import flash.display.StageScaleMode; 
import flash.events.Event; 

public class StageWebViewExample extends MovieClip{

    private var webView:StageWebView = new StageWebView();

    public function StageWebViewExample() 
    {

        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;

        webView.stage = this.stage;
        webView.viewPort = new Rectangle( 0, 0, stage.fullScreenWidth, stage.fullScreenHeight );
        webView.loadURL( "http://www.google.com" );

        stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );
    }

    private function onKey( event:KeyboardEvent ):void
    {
        if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled )
        {
            trace("Back.");
            webView.historyBack();
            event.preventDefault();
        }

        if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled )
        {
            trace("Forward.");
            webView.historyForward();
        }
    }
   }
 }