在 AIR/AS3 中使用特定于移动设备的类测试代码时,如何避免出现VerifyError?

发布于 2024-09-27 09:01:33 字数 1869 浏览 1 评论 0原文

我是一位经验丰富的 AS3 开发人员,第一次进行 AIR 开发是为了创建 iPhone 应用程序。我尝试使用 StageOrientationEvent 和相关类来考虑可变设备方向,并且在尝试在桌面计算机上进行测试时收到了VerifyError,大概是因为与方向相关的类是特定于移动设备的。

iPhone 打包程序的 Adob​​e 文档暗示,只要您在实际使用之前使用 Stage.supportsOrientationChange 等标志来测试功能,就可以测试包含特定于移动设备的代码的应用程序。不幸的是,AIR 似乎在启动时检查不可接受的类,因此该检查是无用的。

如何在桌面上测试此应用程序,而无需在每次切换设备时注释掉特定于移动设备的代码?

相关代码:

package 
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StageOrientationEvent;

public class Main extends Sprite 
{
    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        if (Stage.supportsOrientationChange) 
        {
            stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
        }
    }

    private function onOrientationChange(event:StageOrientationEvent):void
    {
        switch (event.afterOrientation) 
        {
            case StageOrientation.DEFAULT: //ignore.  Landscape.
                break;
            case StageOrientation.ROTATED_RIGHT:
                    stage.setOrientation(StageOrientation.ROTATED_RIGHT);
                break;
            case StageOrientation.ROTATED_LEFT:
                stage.setOrientation(StageOrientation.ROTATED_LEFT);
                break;
            case StageOrientation.UPSIDE_DOWN: //ignore.  Landscape.
                break;
        }
    }
}

}

以及我得到的错误:

[Fault] exception, information=VerifyError: Error #1014: Class flash.events::StageOrientationEvent could not be found.

I'm an experienced AS3 developer doing AIR development for the first time in order to create an iPhone app. I'm trying to account for variable device orientations using the StageOrientationEvent and related classes, and I'm getting a VerifyError when trying to test on a desktop machine, presumably because orientation-related classes are mobile-device specific.

The Adobe docs for the iPhone packager imply that it's possible to test an app containing mobile-specific code, as long as you use flags like Stage.supportsOrientationChange to test for capabilities before actually using them. Unfortunately, it seems like AIR is checking for unacceptable classes at startup, so the check is useless.

How can I test this app on the desktop without commenting out mobile-specific code every time I switch devices?

The relevant code:

package 
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StageOrientationEvent;

public class Main extends Sprite 
{
    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        if (Stage.supportsOrientationChange) 
        {
            stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
        }
    }

    private function onOrientationChange(event:StageOrientationEvent):void
    {
        switch (event.afterOrientation) 
        {
            case StageOrientation.DEFAULT: //ignore.  Landscape.
                break;
            case StageOrientation.ROTATED_RIGHT:
                    stage.setOrientation(StageOrientation.ROTATED_RIGHT);
                break;
            case StageOrientation.ROTATED_LEFT:
                stage.setOrientation(StageOrientation.ROTATED_LEFT);
                break;
            case StageOrientation.UPSIDE_DOWN: //ignore.  Landscape.
                break;
        }
    }
}

}

And the error I get:

[Fault] exception, information=VerifyError: Error #1014: Class flash.events::StageOrientationEvent could not be found.

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

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

发布评论

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

评论(2

难得心□动 2024-10-04 09:01:33

我发现处理此问题的最佳方法是使用 if 语句包装代码,如下所示:

if(ApplicationDomain.currentDomain.hasDefinition("flash.events.StageOrientationEvent")){
    if(Stage.supportsOrientationChange)
    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChange);
}

然后添加通用事件函数并将生成的事件转换为 StageOrientationEvent 类:

private function orientationChange(event : Event):void{
    switch ((event as StageOrientationEvent).afterOrientation) {
        case StageOrientation.DEFAULT:
           break;
    }
}

The best way I have found to handle this is by wrapping the code with an if statement as such:

if(ApplicationDomain.currentDomain.hasDefinition("flash.events.StageOrientationEvent")){
    if(Stage.supportsOrientationChange)
    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChange);
}

Then adding a generic event function and casting the resulting event to the StageOrientationEvent class:

private function orientationChange(event : Event):void{
    switch ((event as StageOrientationEvent).afterOrientation) {
        case StageOrientation.DEFAULT:
           break;
    }
}
一城柳絮吹成雪 2024-10-04 09:01:33

删除或注释所有不需要的内容,或者不完全支持的内容,以便在桌面内进行测试。您可以做的其他事情是尝试除 StageOrientation 之外的另一种解决方法。有一个很好的例子,使用加速器和舞台宽度和高度来获取设备方向。

Remove or comment everything you don't need or it is not fully supported in order to test inside desktop. Other thing you cand do is to try another workaround besides StageOrientation. There is a nice example of using accelerator and Stage Width and Height for obtaining device orientation.

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