Hi, what´s the easiest way to get an iterable object as known from JS and AS3. I want to do this:
var obj = { foo:123, foo2:"somebar", boolfoo:false };
for (v in obj) {
trace(v, obj[v]);
}
thx
Hi, what´s the easiest way to get an iterable object as known from JS and AS3. I want to do this:
var obj = { foo:123, foo2:"somebar", boolfoo:false };
for (v in obj) {
trace(v, obj[v]);
}
thx
var obj = { foo:123, foo2:"somebar", boolfoo:false };
var objKeys = Reflect.fields(obj);
for (key in objKeys) {
trace(key, Reflect.getProperty(obj, key));
}
Thanks flashup, but I don´t like to having to reflect the object every time I want to iterate it. Is there another Object type that would fit for Iteration like this?
var map:Map<String, Dynamic> = ["foo" => 123, "foo2" => "somebar", "boolfoo" => false];
for(key in map.keys()) {
trace(key + " => " + map[key]);
}
Perhaps we could build iteration and array access into “openfl.utils.Object”? That could be nice.
Like this (if it was implemented):
var obj:Object = { foo:123, foo2:"somebar", boolfoo:false };
for (v in obj) {
trace(v, obj[v]);
}
That would be perfect for the AS3-crowd
Thanks to a little help, this now works advertised
So this is implemeted now?
Sorry, I´m not sure if I understand your post, I´m no native speaker
Yes, it is now in the latest OpenFL release:
import openfl.utils.Object;
...
var data:Object = { hello: "World", cool: 100 };
for (field in data) {
trace (field);
trace (data[field]);
}
Awesome! This should really be part of Haxe (Yeah, I know there’s a really long debate about this issue)
Edit: By the way, is there an impact on performance wen using it?
It’s not as fast as working with static data types (obviously), but it’s the same performance as running Reflect.fields
and Reflect.field
over the object