在 flex 移动应用程序中打开网页 [英] Open a web page in a flex mobile app

查看:29
本文介绍了在 flex 移动应用程序中打开网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Flex 移动应用程序,我使用了 navigateToURL 功能,它在默认的网络浏览器中打开网页,但我想在单击按钮时将网页打开到应用程序中.

I am developing a Flex mobile app, I use the navigateToURL function, It open the web page into the default web browser but I would like to open the web page into the application when I click on the button.

我的应用程序的完整代码:

The full code of my app:

     <?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        title="Test">



<fx:Script>

    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    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 mx.events.FlexEvent; 
        private var browser:StageWebView;
        protected function onViewCreated(event:FlexEvent):void
        {
            browser = new StageWebView();
            browser.viewPort = new Rectangle(0, 0, 100, 200);
            browser.stage = this.stage;
            browser.loadURL("http://stackoverflow.com");
        }       

        </fx:Script>



<s:Button x="209" y="67" label="test" click="event" />


 </s:View>

推荐答案

查看 StageWebView 类,它应该适合您想要做的事情.

Take a look at the StageWebView class, it should fit to what you want to do.

这是我如何使用它的示例代码:

Here is a sample code of how I'm using it:

    private var browser:StageWebView;
    protected function onViewCreated(event:FlexEvent):void
    {
        browser = new StageWebView();
        browser.viewPort = new Rectangle(0, 0, 100, 200);
        browser.stage = this.stage;
        browser.addEventListener(Event.COMPLETE, onBrowserLoaded);
        browser.loadURL("http://stackoverflow.com");
    }

在这种情况下,一旦创建视图,浏览器就会在指定的坐标处打开.但是您可以在按钮的点击事件上显示它,或者触发一个弹出窗口或另一个充当容器的视图.

In this case the browser is opened at the specified coordinates as soon as the view is created. But you could display it on the click event of your button, or trigger a pop-up or another view that will act as a container.

编辑:根据您在第一篇文章中编辑的内容,您只需修复点击处理程序,以便在点击按钮时调用您的代码.暂时不是.请尝试以下操作:

EDIT: From what you've edited in your first post, you just have to fix the click handler so your code will be called when clicking the button. For the moment it's not. Try the following:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    title="Test">


<fx:Script>
    <![CDATA[

import flash.net.URLRequest;
import flash.net.navigateToURL;
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 mx.events.FlexEvent; 
    private var browser:StageWebView;
    protected function onButtonClicked(event:MouseEvent):void
    {
        browser = new StageWebView();
        browser.viewPort = new Rectangle(0, 0, 100, 200);
        browser.stage = this.stage;
        browser.loadURL("http://stackoverflow.com");
    }       

    ]]>
    </fx:Script>

<s:Button x="209" y="67" label="test" click="onButtonClicked(event)" />

EDIT2:根据您的要求,您可以使用另一个功能来关闭浏览器.假设您想在单击按钮时执行此操作,它将是这样的:

EDIT2: As you requested, you can use another function to close the browser. Assuming you want to do so when clicking a button, it would be something like this:

protected function onButton2Clicked(event:MouseEvent):void
{
    browser.dispose();
}    

以及按钮声明(包含在导航按钮中):

And the button declaration (contained in the Navigation button):

<s:actionContent>
    <s:Button label="Close Browser" click="onButton2Clicked(event)" />
</s:actionContent>

如果您使用 actionContent 工具栏,您应该找到一种有趣的方式来完成您正在搜索的工作.

If you play around with the actionContent Toolbar, you should find an interesting way to do what you're searching for.

这篇关于在 flex 移动应用程序中打开网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆