webstageview没有加载到手机上但在模拟器中工作

时间:2011-11-15 16:02:07

标签: flex flash-builder

我正在尝试使用webstageview加载本地html文件....此代码在模拟器上运行完美,但是当我在我的Android设备上运行它(运行android 2.3)时,它不起作用.. .. ..只是创建一个空白的webstageview永远不会加载本地的html文件...缩放功能是完整的所以我知道它打开webstageview,但我从来没有看到内容....任何建议?我被卡住了......

<?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"
    xmlns:ns1="*"
    xmlns:controls="com.flexcapacitor.controls.*"
    actionBarVisible="false" backKeyPressed="onBackKeyPressed(event)"
    creationComplete="view1_creationCompleteHandler(event)" title="{data.image}"
    xmlns:components="com.flexcapacitor.components.*">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        import spark.components.ViewNavigator;

        public var webView1:StageWebView=new StageWebView();


        protected function view1_creationCompleteHandler(event:FlexEvent):void
        {

            webView1.stage=this.stage;
            webView1.viewPort=new Rectangle(0,50,stage.stageWidth, stage.stageHeight);
            var fPath:String=new File(new File("app:/"+data.html).nativePath).url;
            webView1.loadURL(fPath);


        }
        protected function onBackKeyPressed(event:FlexEvent):void{
            webView1.viewPort = null;
            webView1.dispose();
            webView1 = null;
        }


        protected function backbutton_clickHandler(event:MouseEvent):void
        {
            webView1.viewPort = null;
            webView1.dispose();
            webView1 = null;
            navigator.popView();
        }

    ]]>
</fx:Script>
<s:Button id="backbackbutton" x="0" y="0" width="100%" height="50" label="Back" click="backbutton_clickHandler(event)"/>

2 个答案:

答案 0 :(得分:1)

我最终不得不制作一些临时文件才能正确打开它....不知道为什么它之前无法工作,即使模拟器工作正常......这里的代码有效:

<?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"
    xmlns:ns1="*"
    xmlns:controls="com.flexcapacitor.controls.*"
    actionBarVisible="false" backKeyPressed="onBackKeyPressed(event)"
    creationComplete="view1_creationCompleteHandler(event)" title="{data.image}"
    xmlns:components="com.flexcapacitor.components.*">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        import spark.components.ViewNavigator;

        public var webView1:StageWebView=new StageWebView();


        protected function view1_creationCompleteHandler(event:FlexEvent):void
        {

            webView1.stage=this.stage;
            webView1.viewPort=new Rectangle(0,50,stage.stageWidth, stage.stageHeight);
          var fa:File = File.applicationDirectory.resolvePath(data.html);
            var f2a:File = File.createTempDirectory();
            var fb:File = File.applicationDirectory.resolvePath(data.location);
            fa.copyTo(f2a.resolvePath(data.html),true);
            fb.copyTo(f2a.resolvePath(data.location),true);
            webView1.loadURL(f2a.url + File.separator +data.html);


        }
        protected function onBackKeyPressed(event:FlexEvent):void{
            webView1.viewPort = null;
            webView1.dispose();
            webView1 = null;
        }


        protected function backbutton_clickHandler(event:MouseEvent):void
        {
            webView1.viewPort = null;
            webView1.dispose();
            webView1 = null;
            navigator.popView();
        }

    ]]>
</fx:Script>
<s:Button id="backbackbutton" x="0" y="0" width="100%" height="50" label="Back"
          accentColor="#000000" chromeColor="#404040" click="backbutton_clickHandler(event)"
          color="#FFFFFF"/>

答案 1 :(得分:0)

您是否已将“app”文件夹添加到构建路径中,以便html文件包含在您的发布版本中?如果没有,请右键单击您的项目并转到属性&gt; Actionscript构建路径&gt;源路径&gt;添加文件夹...