2012-02-14 41 views
3

我使用Flash Air开发iOS游戏。能够从您的应用程序中启动浏览器会很好。任何想法,将不胜感激!!Flash Air iOS开发:是否可以从您的应用程序中启动浏览器?

+0

备注以下问题的答案:'StageWebView'打开了一个定义的矩形_within_您的应用程序的网页,而'navigateToURL'启动Safari浏览器_你的应用程序。这个问题似乎有点模棱两可,但下面两个答案都很好地提出。 :) – 2014-11-10 21:57:17

回答

2

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

import flash.net.navigateToURL; 
import flash.net.URLRequest; 

navigateToURL(new URLRequest("http://google.com"), "_blank"); 
+0

但是这段代码会退出我的应用程序并打开浏览器。我想保持用户在我的应用程序... – user867556 2012-02-14 07:24:40

+0

而不是“_blank”,你可以尝试“_self”或其他一些。如果这没有帮助,阿德里安的答案似乎更有希望。 – ToddBFisher 2012-02-14 15:27:04

3

您可以使用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()); 
} 
相关问题