是否可以获取flash(AS3)中的所有成员变量?

发布于 2024-08-29 06:03:44 字数 107 浏览 11 评论 0原文

我正在尝试获取 AS3 中的所有成员变量,然后对于每个我想以各种方式处理它的成员变量。我需要名称,然后如果它是某种类型的集合,我也想循环遍历该集合。我试图以某种自定义的方式进行本质上的序列化。 谢谢!

I am trying grab all the member variables in AS3, and then foreach one i would like to process it in various ways. I would need the name and then if it is a collection of some type I would like to loop through that collection as well. I am attempting to essentially serialize in a somewhat custom fashion.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-09-05 06:03:44

如果您想要序列化一个对象,您肯定会想使用 JSON。

JSON 基本上将对象转换为字符串,也使用encode()/serialize() 和decode()/deserialize() 函数将对象转换为字符串。

AS3 中有一个内置的 JSON 类,并且非常易于使用。

一旦你做了类似的事情:

var myObject:Object = {};
var myObjectString:String = JSON.serialize(myObject);

获取字符串后,你可以执行所有开关逻辑来操作每个不同的变量,并通过 deserialize() 函数将其转换回对象。

If you're looking to serialize an object, you will definitely want to use JSON.

JSON basically converts objects into strings and also the other way round using an encode()/serialize() and decode()/deserialize() function.

There is a built-in JSON class in AS3, and it's really easy to use.

Once you do something like:

var myObject:Object = {};
var myObjectString:String = JSON.serialize(myObject);

After getting the string, you can do all your switch logic to manipulate each of your different variables and convert it back into an object via the deserialize() function.

江南月 2024-09-05 06:03:44

您可以使用describeType。它以 XML 形式返回有关该对象的信息。默认情况下,您可以迭代对象中的公共属性。您可以尝试类似...

// the object to iterate over
var someObj:Object = {};

for(var prop:String in someObj) {
    // check to see if its something you want to iterate over
    if (someObj[prop] is Array) {
        // iterator over the property here
    }
}

我希望这能回答您的问题。

You could use describeType. That returns information about the object as XML. By default, you can iterate over public properties in objects. You could try something like...

// the object to iterate over
var someObj:Object = {};

for(var prop:String in someObj) {
    // check to see if its something you want to iterate over
    if (someObj[prop] is Array) {
        // iterator over the property here
    }
}

I hope this answers your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文