Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在AIR/AS3中使用特定于移动设备的类测试代码时,如何避免验证错误?_Iphone_Actionscript 3_Air_Verifyerror - Fatal编程技术网

Iphone 在AIR/AS3中使用特定于移动设备的类测试代码时,如何避免验证错误?

Iphone 在AIR/AS3中使用特定于移动设备的类测试代码时,如何避免验证错误?,iphone,actionscript-3,air,verifyerror,Iphone,Actionscript 3,Air,Verifyerror,我是一名经验丰富的AS3开发人员,第一次进行AIR开发以创建iPhone应用程序。我试图使用StageOrientationEvent和相关类来解释可变的设备方向,当我试图在台式机上进行测试时,我得到了一个VerifyError,可能是因为方向相关类是特定于移动设备的 适用于iPhone packager的Adobe文档暗示,只要在实际使用之前使用Stage.supportsOrientationChange等标志来测试功能,就可以测试包含特定于移动设备的代码的应用程序。不幸的是,AIR似乎在启

我是一名经验丰富的AS3开发人员,第一次进行AIR开发以创建iPhone应用程序。我试图使用StageOrientationEvent和相关类来解释可变的设备方向,当我试图在台式机上进行测试时,我得到了一个VerifyError,可能是因为方向相关类是特定于移动设备的

适用于iPhone packager的Adobe文档暗示,只要在实际使用之前使用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.

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

我发现处理这一问题的最好方法是用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;
    }
}