【问题标题】:Flash Air iOS Development: Is it possible to launch a browser from within your applications?Flash Air iOS 开发:是否可以从您的应用程序中启动浏览器?
【发布时间】:2012-02-14 06:43:44
【问题描述】:

我使用 Flash Air 开发 iOS 游戏。如果能够从您的应用程序中启动浏览器,那就太好了。任何想法将不胜感激!

【问题讨论】:

  • 请注意以下答案:StageWebView 在您的应用程序 定义的矩形中打开网页,而navigateToURL 启动Safari 浏览器i> 你的应用程序。这个问题似乎有点模棱两可,但两个答案都很好地呈现在下面。 :)

标签: ios flash browser air


【解决方案1】:

您可以使用StageWebView 在您的 AIR 应用程序中打开网页。

以下是在屏幕右半部分(即舞台)打开页面的示例用法:

private var _web_view:StageWebView;
private function init_stagewebview(url:String):void 
{
  if (_web_view) {
    throw new Error('init_stagewebview() called with existing _web_view - you must call cleanup first');
  }
  _web_view = new StageWebView();
  var stage:Stage = NativeApplication.nativeApplication.activeWindow.stage;
  _web_view.stage = stage;
  _web_view.viewPort = new Rectangle(stage.stageWidth/2,0,stage.stageWidth/2, stage.stageHeight);
  _web_view.addEventListener(ErrorEvent.ERROR, handle_error);
  _web_view.addEventListener(IOErrorEvent.IO_ERROR, handle_error);
  _web_view.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handle_error); 
  _web_view.addEventListener(LocationChangeEvent.LOCATION_CHANGING, handle_loc_change);
  _web_view.loadURL(url);
}

private function handle_loc_change(e:LocationChangeEvent=null):void 
{ 
  if (e) {
    var loc:String = e.location;
    trace(" -- webView location changed to: "+loc);

    // Disable the navigation if you want to (this is a common
    // way of passing data from web to AIR):
    // e.preventDefault();
  }
}

private function cleanup_web_view():void 
{
  if (_web_view == null) return;
  _web_view.removeEventListener(ErrorEvent.ERROR, handle_error);
  _web_view.removeEventListener(IOErrorEvent.IO_ERROR, handle_error);
  _web_view.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, handle_error);
  _web_view.removeEventListener(LocationChangeEvent.LOCATION_CHANGING, handle_loc_change);
  _web_view.viewPort = null;
  _web_view.dispose();
  _web_view = null;
}

private function handle_error(e:ErrorEvent):void 
{ 
  if (e) trace("- - - - webView Error:" + e.toString());
}

【讨论】:

    【解决方案2】:

    从 AIR 应用程序调用 navigateToURL() (docs) 会将系统浏览器应用程序启动到您指定的 URL(将您的应用程序留在后台):

    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    
    navigateToURL(new URLRequest("http://google.com"), "_blank");
    

    【讨论】:

    • 但是这段代码会退出我的应用程序并打开浏览器。我想让用户留在我的应用中...
    • 您可以尝试“_self”或其他一些,而不是“_blank”。如果这没有帮助,Adrian 的回答似乎更有希望。
    【解决方案3】:

    使用 AIR 特定的类 HTMLControl 怎么样? 据我了解,您希望使用屏幕应用的一部分启用网络导航。

    http://www.mikechambers.com/blog/2007/11/09/using-the-htmlcontrol-in-adobe-air-to-parse-html-as-a-data-source/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 2016-09-11
      相关资源
      最近更新 更多