【问题标题】:How do functions with multiple parameters of the same name work?具有多个同名参数的函数如何工作?
【发布时间】:2019-08-14 06:34:57
【问题描述】:

我一直在查看 Flash 游戏的代码 (link)。但是,我无法理解其中一些函数是如何工作的,尤其是因为其中一些函数具有我认为无法通过编译器的函数定义。

以下是来自 TodCommon.as 的一些代码,它似乎与自身冲突(或至少使用了错误的命名约定)。

private static var gFlashingColor:Color = new Color();

final public static function ClampFloat(ClampInt:Number, ClampInt:Number, ClampInt:Number) : Number
{
    if(ClampInt <= ClampInt)
    {
        return ClampInt;
    }
    if(ClampInt >= ClampInt)
    {
        return ClampInt;
    }
    return ClampInt;
}

final public static function ClampInt(gFlashingColor:int, gFlashingColor:int, gFlashingColor:int) : int
{
    if(gFlashingColor <= gFlashingColor)
    {
        return gFlashingColor;
    }
    if(gFlashingColor >= gFlashingColor)
    {
        return gFlashingColor;
    }
    return gFlashingColor;
}


代码中还有我见过的最奇怪的 for-each 循环语法(这个例子还包含一个包名作为参数名)

public function CountPlantByType(com.popcap.flash.framework.resources.fonts:int) : int
{
    var _loc_3:CPlant = null;
    var _loc_2:int = 0;
    var _loc_4:int = 0;
    var _loc_5:* = this.mPlants;
    while(<to complete>)
    {
        _loc_3 = __nextvalue;
        if(_loc_3.mSeedType != com.popcap.flash.framework.resources.fonts)
        {
            break;
        }
        _loc_2++;
    }
    return _loc_2;
}

这些只是我认为看起来非常奇怪并且难以理解的一些例子。但是这些函数都可以工作并且在整个代码中被广泛使用。有人可以解释 ClampFloat 和 ClampInt 函数是如何工作的,或者为什么使用包名作为参数是合法的?谢谢

【问题讨论】:

    标签: actionscript


    【解决方案1】:

    已解决。原来我用来从 SWF 中提取这些文件的程序在此过程中也损坏了它们。使用 JPEXS Free Flash Decompiler 而不是 ActionScriptExtractor 修复了代码语法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 2021-09-06
      • 2016-02-04
      • 1970-01-01
      相关资源
      最近更新 更多