【问题标题】:Open a web page in a flex mobile app在 flex 移动应用中打开网页
【发布时间】:2014-01-28 14:17:09
【问题描述】:

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

我的应用的完整代码:

     <?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>

【问题讨论】:

    标签: android apache-flex mobile web adobe


    【解决方案1】:

    看看StageWebView 类,它应该适合你想做的事情。

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

        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");
        }
    

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

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

    <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: 根据您的要求,您可以使用其他功能关闭浏览器。假设您想在单击按钮时这样做,它会是这样的:

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

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

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

    如果您使用actionContent Toolbar,您应该会找到一种有趣的方式来做您正在搜索的事情。

    【讨论】:

    • 你有没有得到任何错误?这段代码是在视图中执行的还是在其他地方执行的?
    • 我收到此错误 1046: Ce type est introuvable ou n'est pas une constante de compilation : FlexEvent.
    • 我明白了,你当然应该修改我给你的代码。首先,该错误意味着您没有输入“import mx.events.FlexEvent;”在你上课的开始。其次,请记住,您可以根据调用此函数的方式更改事件类型(从按钮单击调用它将是 MouseEvent)
    • 1151: Conflit dans la definition browser dans l'espace de nom internal.
    • 您的代码中是否还有其他名为“浏览器”的内容?尝试重命名它。
    【解决方案2】:

    觉得效果不错,

    <s:navigationContent>
        <s:Button  click="onButtonCClicked(event)"  icon="@Embed('logo3/back3.png')"/>
    </s:navigationContent>
    
    <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; 
                import flash.display.MovieClip; 
                import flash.media.StageWebView; 
                import flash.geom.Rectangle; 
    
                private var browser:StageWebView;
                protected function onButtonClicked(event:MouseEvent):void
                {
                    browser = new StageWebView();
                    browser.viewPort = new Rectangle(0, 70, 500, 400);
                    browser.stage = this.stage;
                    browser.loadURL("http://stackoverflow.com");
                }  
    
                protected function onButtonCClicked(event:MouseEvent):void
                {
                    browser.dispose();
                    navigator.pushView(menu)
                }   
                protected function onButtonRClicked(event:MouseEvent):void
                {
                    browser.reload();
    
                }  
    
    
    
    
    
    
    
            ]]>
    </fx:Script>
    <s:Button x="209" y="67" label="test" click="onButtonClicked(event)" />
    

    【讨论】:

      猜你喜欢
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多