Actionscript:将函数从AS3转换为AS2

时间:2013-06-19 13:48:07

标签: actionscript-3 actionscript actionscript-2

需要从数组中获取重复值,并获取下面的代码,但在AS3中运行良好

请有人将此AS3代码转换为AS2吗?

var array:Array = [1,2,3,4,3];

// create a dictionary and go through our array, pulling out the values
var dict:Dictionary = new Dictionary();
var len:int         = array.length;
for( var i:int = 0; i < len; i++ )
{
    var val:int = array[i]; // get the value from the array
    if( !( val in dict ) )  // if it's not in our dictionary, create a new array
        dict[val] = [];
    dict[val].push( i );    // add the index of the value to the array
}

// now go through our dictionary, finding the duplications
for( var key:* in dict )
{
    var indicies:Array = dict[key];
    if( indicies.length <= 1 )
        continue; // single value - ignore
    trace( "The value " + key + " is repeated " + indicies.length + " times. Indicies: " + indicies );
}
  • 错误代码:

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 2 Impossible de charger la classe ou l'interface'Fictionary'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 3 Impossible de charger la classe ou l'interface'int'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 4 Impossible de charger la classe ou l'interface'int'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 6 Impossible de charger la classe ou l'interface'int'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 7')'attendu

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 10'}'inattendu

1 个答案:

答案 0 :(得分:0)

怎么样:

var array:Array = [1,2,3,4,3];
var obj:Object = new Object();

for( var i:int = 0; i < array.length; i++ )
{
   if( obj[ array[i]] === undefined )
   {
        obj[ array[ i ]] = i;
   }
   else trace( "the value " + array[i] + " from location " + obj[ array[ i ]] + " is repeated at location " + i );
}

(这只是p代码。我面前没有编译器。)

你想对结果做什么?