如何在 ActionScript 3.0 中找到关联数组的长度? [英] How do I find the length of an associative array in ActionScript 3.0?

查看:20
本文介绍了如何在 ActionScript 3.0 中找到关联数组的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在 ActionScript 3.0 中检索关联数组(实现为 Object)的长度?

Is there a simple way to retrieve the length of an associative array (implemented as an Object) in ActionScript 3.0?

我了解在 AS3 中创建关联数组有两种主要方法:

I understand that there are two primary ways of creating associative arrays in AS3:

  1. 使用Dictionary 对象;当键不需要是 string
  2. 时特别方便
  3. 使用Object,并为每个所需元素简单地创建属性.属性名称是键,值就是值.
  1. Use a Dictionary object; especially handy when the key does not need to be a string
  2. Use an Object, and simply create properties for each desired element. The property name is the key, and the value is, well, the value.

我的应用程序使用方法#2(使用Object 类来表示关联数组).

My application uses approach #2 (using the Object class to represent associative arrays).

我希望有比我的 for 循环更原生的东西,它手动计算所有元素.

I am hoping there is something more native than my for loop, which manually counts up all the elements.

推荐答案

你必须像你一样在 for 循环中计算它们.当然,您可以创建一个类并将 for 循环粘贴到该类中.

You have to count them in a for loop as you do. Of course, you could make a class and stick the for loop in that class.

有关 AS3 中集合的一些出色实现,请查看这些人.

For some great implmentations of Collections in AS3, check these guys.

Edit 2013 不出所料,链接确实会中断.试试这个新的:http://www.grindheadgames.com/get-对象的长度.

Edit 2013 Not surprisingly, links do break after time. Try this new one: http://www.grindheadgames.com/get-the-length-of-an-object.

这篇关于如何在 ActionScript 3.0 中找到关联数组的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆