quarta-feira, 26 de outubro de 2011

Abrir Página da internet no Flex Mobile

<?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="HTML Content" viewActivate="view1_viewActivateHandler(event)">
   
    <fx:Script>
        <![CDATA[
            import flash.media.StageWebView;
            import flash.net.URLRequest;
            import spark.events.ViewNavigatorEvent;
           
            protected var webView:StageWebView = new StageWebView();
            protected var openBrowser:Boolean = false;
           
           
            protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
            {
                if (StageWebView.isSupported)
                {
                    currentState = "normal";
                    webView.stage = stage;
                    webView.viewPort = new Rectangle(20, 100, 450, 450);
                    webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLChange);   
                    webView.loadURL("http://vitorhansen.blogspot.com");   
                    addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
                }
                else {
                    currentState = "unsupported";
                    lblSupport.text = "StageWebView feature not supported";
                }   
            }
           
            protected function onURLChange(event:LocationChangeEvent):void
            {
                trace("URL change");
                // Uncomment the following line to load in the default browser instead...
                //navigateToURL(new URLRequest(event.location));
            }
           
            protected function onRemove(event:ViewNavigatorEvent):void
            {
                this.webView.dispose();
            }
        ]]>
    </fx:Script>
   
    <s:states>
        <s:State name="normal"/>
        <s:State name="unsupported"/>
    </s:states>
   
    <s:Label id="lblSupport" includeIn="unsupported" width="95%" horizontalCenter="0" verticalCenter="0"/>
    <s:TextArea bottom="5" width="95%" includeIn="normal" horizontalCenter="0" enabled="false" editable="false"
                text="Exemplo Página Flex."/>
</s:View>

Vitor Yudi Hansen