AS3:is运算符右侧的表达式必须是一个类

时间:2016-04-06 08:16:44

标签: actionscript-3 flash exception

        public static const DIAGONAL_HEURISTIC:Function = function (tile:IAstarTile, req:PathRequest):Number {
        var start:Point = (tile as IPositionTile).getPosition();
        var end:Point = (req.getEnd() as IPositionTile).getPosition();

        var xd:int = Math.abs(end.x - start.x);
        var yd:int = Math.abs(end.y - start.y);
        if (xd > yd) {
            return diagonalMultiplier * (req.getMap() as Map).getDefaultCost() * yd + normalMultiplier * (req.getMap() as Map).getDefaultCost() * (xd - yd);
        } else {
            return diagonalMultiplier * (req.getMap() as Map).getDefaultCost() * xd + normalMultiplier * (req.getMap() as Map).getDefaultCost() * (yd - xd);
        }
    }

嗨,我回来了exception, information=TypeError: Error #1041: RHS of operator must be a Class。代码取自repo。为什么会引起异常?

更新

错误是由以下一行引起的:

(req.getMap() as Map).getDefaultCost() .... etc

Map实现(接口)IMap,但在上面的行中Map不被视为类,因此使用as运算符会触发异常错误。

注意:此异常由AIR SDK 3.5触发,但未通过AIR SDK 3.1触发

见图片: Debug screenshot

1 个答案:

答案 0 :(得分:0)

类映射实现(接口)IMap。在行中:$ wget https://phar.phpunit.de/phpunit-old.phar --2016-04-07 09:47:35-- https://phar.phpunit.de/phpunit-old.phar Resolving phar.phpunit.de (phar.phpunit.de)... 188.94.27.25 Connecting to phar.phpunit.de (phar.phpunit.de)|188.94.27.25|:443... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: https://phar.phpunit.de/phpunit-4.8.24.phar [following] --2016-04-07 09:47:35-- https://phar.phpunit.de/phpunit-4.8.24.phar Reusing existing connection to phar.phpunit.de:443. HTTP request sent, awaiting response... 200 OK Length: 3086772 (2.9M) [application/octet-stream] Saving to: ‘phpunit-old.phar’ phpunit-old.phar 100%[=====================================================================================================================================>] 2.94M 3.97MB/s in 0.7s 2016-04-07 09:47:36 (3.97 MB/s) - ‘phpunit-old.phar’ saved [3086772/3086772] $ php phpunit-old.phar --version PHPUnit 4.8.24 by Sebastian Bergmann and contributors. - 地图不是类,运算符'为'发送一个例外。 AIR SDK 3.5触发了异常,而不是在AIR SDK 3.1上触发。