Flex Mobile 为什么要 persistNavigatorState="true"和 stage.setAspectRatio(StageAspectRatio.PORTRAIT) 不混合?

发布于 2024-12-15 06:51:12 字数 2452 浏览 6 评论 0 原文

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

<s:View ...creationComplete="init()">

受保护的函数 init():void {

stage.setAspectRatio(StageAspectRatio.PORTRAIT);
}

    [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()"

    protected  function init():void {


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

    }

Why can't I use persistNavigatorState="true" and stage.setAspectRatio(StageAspectRatio.PORTRAIT) together in initializing program.

<s:View ...creationComplete="init()">

protected function init():void {

stage.setAspectRatio(StageAspectRatio.PORTRAIT);
}

    [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]

Whenever I enable persistNavigatorState, my program won't run. Is there a way to use both together? Thanks

[Line 4] creationComplete="init()"

    protected  function init():void {


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

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

峩卟喜欢 2024-12-22 06:51:12

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

您可以尝试在 app.xml 中包含 portrait 进行设置,而不是在creationComplete 上使用 stage.setAspectRatio(StageAspectRatio.PORTRAIT) 。

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

参考资料:

Perhaps the creationComplete event fires before the stage is accessable. Using persistNavigatorState changes the startup behavior of your application a bit by first fetching your navigator's state info from the persistence cache. This line in the Flex docs is quite telling: when the application restarts, only the state of the current ViewNavigator is restored. Also, the stage in flex is not accessable until an object is added to the displayList. So if you call setAspectRatio when the stage is empty, you will get a null obj reference.

Instead of using stage.setAspectRatio(StageAspectRatio.PORTRAIT) on creationComplete, you can try setting including <aspectRatio>portrait</aspectRatio> in your app.xml.

Or, you could listen for the addedToStage event in your view, and call stage.setAspectRatio(StageAspectRatio.PORTRAIT) in the event handler. That way you know for sure that the stage is available.

References:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文