首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么stage.setAspectRatio(StageAspectRatio.PORTRAIT)和persistNavigatorState=“真”不混在一起?

为什么stage.setAspectRatio(StageAspectRatio.PORTRAIT)和persistNavigatorState=“真”不混在一起?
EN

Stack Overflow用户
提问于 2011-11-15 02:36:01
回答 1查看 965关注 0票数 0

为什么在初始化程序时不能同时使用persistNavigatorState="true"stage.setAspectRatio(StageAspectRatio.PORTRAIT)

代码语言:javascript
复制
<s:View ...creationComplete="init()">

受保护函数init():void { stage.setAspectRatio(StageAspectRatio.PORTRAIT); }

代码语言:javascript
复制
    [SWF] Main.swf - 3,394,828 bytes after decompression
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at views::Try01/init()[C:\Users\James\Adobe Flash Builder 4.5\myProgram\src\views\Try01.mxml:19]
    at views::Try01/___Try01_View1_creationComplete()[C:\Users\James\Adobe Flash Builder 4.5\myProgram\src\views\Try01.mxml:4]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
    at mx.core::UIComponent/set initialized()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
    at mx.managers::LayoutManager/validateClient()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1090]
    at mx.core::UIComponent/validateNow()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8067]
    at spark.components::ViewNavigator/commitNavigatorAction()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1878]
    at spark.components::ViewNavigator/commitProperties()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1236]
    at mx.core::UIComponent/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8209]
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:783]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]

每当我启用persistNavigatorState时,我的程序就不会运行。有办法把两者结合起来吗?谢谢

第4行creationComplete="init()"

代码语言:javascript
复制
    protected  function init():void {


[Line 19]  stage.setAspectRatio(StageAspectRatio.PORTRAIT);

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-15 15:19:34

也许creationComplete事件在舞台可访问之前触发。使用persistNavigatorState会稍微改变应用程序的启动行为,首先从持久性缓存中获取导航器的状态信息。Flex文档中的这一行很有说服力:当应用程序重新启动时,只有当前ViewNavigator的状态被恢复。另外,在将对象添加到displayList之前,flex中的阶段是不可访问的。因此,如果在舞台为空时调用setAspectRatio,您将得到一个空obj引用。

您可以尝试在您的stage.setAspectRatio(StageAspectRatio.PORTRAIT)中设置<aspectRatio>portrait</aspectRatio>,而不是在creationComplete上使用<aspectRatio>portrait</aspectRatio>

或者,您可以在视图中侦听addedToStage事件,并在事件处理程序中调用stage.setAspectRatio(StageAspectRatio.PORTRAIT)。这样你就可以确定舞台是可用的了。

参考文献:

  • Adobe启用移动应用程序中的持久性
  • Flex移动应用程序中的Flex定位与deviceOrientation
  • Anselm在CreationComplete之后,Flex组件的舞台属性是…什么?零?
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8130827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档