【发布时间】:2012-02-14 06:43:44
【问题描述】:
我使用 Flash Air 开发 iOS 游戏。如果能够从您的应用程序中启动浏览器,那就太好了。任何想法将不胜感激!
【问题讨论】:
-
请注意以下答案:
StageWebView在您的应用程序内 定义的矩形中打开网页,而navigateToURL在外 启动Safari 浏览器i> 你的应用程序。这个问题似乎有点模棱两可,但两个答案都很好地呈现在下面。 :)
我使用 Flash Air 开发 iOS 游戏。如果能够从您的应用程序中启动浏览器,那就太好了。任何想法将不胜感激!
【问题讨论】:
StageWebView 在您的应用程序内 定义的矩形中打开网页,而navigateToURL 在外 启动Safari 浏览器i> 你的应用程序。这个问题似乎有点模棱两可,但两个答案都很好地呈现在下面。 :)
您可以使用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());
}
【讨论】:
从 AIR 应用程序调用 navigateToURL() (docs) 会将系统浏览器应用程序启动到您指定的 URL(将您的应用程序留在后台):
import flash.net.navigateToURL;
import flash.net.URLRequest;
navigateToURL(new URLRequest("http://google.com"), "_blank");
【讨论】:
使用 AIR 特定的类 HTMLControl 怎么样? 据我了解,您希望使用屏幕应用的一部分启用网络导航。
【讨论】: