When you say "all props" are you talking about completely dynamic
properties (again, note that these loops only take properties
dynamically added at runtime into consideration).
I did a test and I only see dynamic property names or their values
returned in either a "for loop" or "for each in" loop respectively.
Here's the AS code I tried:
//---------------------------------------------
package
{
import flash.display.Sprite;
public class QuickTest extends Sprite
{
public function QuickTest()
{
super();
trace("Starting test...");
var a:A = new A();
var b:B = new B();
b.dynamicProperty = "dynamicPropertyValue";
b.anotherDynamicProperty = "anotherDynamicPropertyValue";
var p:*;
for (p in a)
{
trace("B." + p + "=" + a[p]);
}
for each (p in a)
{
trace("each A = " + p);
}
for (p in b)
{
trace("B." + p + "=" + b[p]);
}
for each (p in b)
{
trace("each B = " + p);
}
trace("Ending test...");
}
}
public dynamic class B
{
public function B()
{
}
public var variableB:String;
public function get propertyB():String
{
return _b;
}
public function set propertyB(value:String):void
{
_b = value;
}
private var _b:String = "propertyBValue";
}
public class A
{
public function A()
{
}
public var variableA:String;
public function get propertyA():String
{
return _a;
}
public function set propertyA(value:String):void
{
_a = value;
}
private var _a:String = "propertyAValue";
}
}
// -----------------------------------
And here's the trace output from flashlog.txt:
Starting test...
B.dynamicProperty=dynamicPropertyValue
B.anotherDynamicProperty=anotherDynamicPropertyValue
each B = dynamicPropertyValue
each B = anotherDynamicPropertyValue
Ending test...
It seems to be working as documented.
Pete
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of leo4beer
Sent: Tuesday, December 12, 2006 8:04 AM
To: [email protected]
Subject: [flexcoders] Re: problem with a "for each" loop
i have another question:
when I do the following:
for(var prop in instancOfB){
//gets here only once as if instancOfB has only one member
}
bur if I do the following:
for each(var prop in instancOfB){
//will show the values of all props
}
the problem is that for each will not give me the prop name but only
the value. a simple "for" gives me a name and value but fails to show
all props.