StageOrientationEvent 未在 ActionScript 3 中调度

发布于 2025-01-04 18:00:49 字数 1682 浏览 0 评论 0原文

我有来自 adobe 论坛的这段代码,它可以在移动应用程序的第一个屏幕上运行。但如果我将此代码放在新视图中(在我推送的视图中),它就不起作用 有人知道这个问题的解决办法吗?

<?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="HomeView" creationComplete="view1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.*;
            protected function view1_creationCompleteHandler(event:FlexEvent):void{
                addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage)
            }
            private function _onAddedToStage(event:Event):void{
                if(stage.autoOrients)                    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, _onStage_OrientationChange);
            }
            private function _onStage_OrientationChange(event:StageOrientationEvent):void{
    switch(event.afterOrientation){
                    case StageOrientation.DEFAULT:
                        trace('DEFAULT')
                        break;
                    case StageOrientation.ROTATED_RIGHT:
                        trace('ROTATED_RIGHT');
                        break;
                    case StageOrientation.ROTATED_LEFT:
                        trace('ROTATED_LEFT');
                        break;
                    case StageOrientation.UPSIDE_DOWN:
                        trace('UPSIDE_DOWN');
                        break;
                    case StageOrientation.UNKNOWN:
                        trace('UNKNOWN');
                        break;
                }
            }
        ]]>
    </fx:Script> 
</s:View>

i have this code from the adobe forum, which works on the first screen of a mobile application. But it doesnt work if i put this code in a new view ( in a view which i have pushed )
Does anybody know the solution to this problem?

<?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="HomeView" creationComplete="view1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.*;
            protected function view1_creationCompleteHandler(event:FlexEvent):void{
                addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage)
            }
            private function _onAddedToStage(event:Event):void{
                if(stage.autoOrients)                    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, _onStage_OrientationChange);
            }
            private function _onStage_OrientationChange(event:StageOrientationEvent):void{
    switch(event.afterOrientation){
                    case StageOrientation.DEFAULT:
                        trace('DEFAULT')
                        break;
                    case StageOrientation.ROTATED_RIGHT:
                        trace('ROTATED_RIGHT');
                        break;
                    case StageOrientation.ROTATED_LEFT:
                        trace('ROTATED_LEFT');
                        break;
                    case StageOrientation.UPSIDE_DOWN:
                        trace('UPSIDE_DOWN');
                        break;
                    case StageOrientation.UNKNOWN:
                        trace('UNKNOWN');
                        break;
                }
            }
        ]]>
    </fx:Script> 
</s:View>

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

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

发布评论

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

评论(1

国粹 2025-01-11 18:00:49

试试这个:

 protected function view1_creationCompleteHandler(event:FlexEvent):void{

        if(stage.autoOrients)       

        stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, _onStage_OrientationChange);

    }

try this:

 protected function view1_creationCompleteHandler(event:FlexEvent):void{

        if(stage.autoOrients)       

        stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, _onStage_OrientationChange);

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