I have an example where I seem to have to refer to a movie
clip by a string of chained property accesses, instead of by the
property access themselves. In the example I am trying to set the
color of a movie clip, but I suspect that this issue is not
specific to the Color class.
You can see in mySetColorVersion1 I take two property name
parameters, plus a color. I access the movie clip I want to color
using a chain of movie clip property accesses (each part of the
chain is a movie clip), using "." for some and "[ ]" for those that
are accessed via variable properties (t and a). mySetColorVersion1
has no effect.
function mySetColorVersion1( t:String, a:String, c:String )
var color:Color = new Color( holder_mc.subholder_mc[ t
].specific_mc[ a ] );
color.setRGB( c ); // does nothing
I had an example from some legacy code that did things as in
mySetColorVersion2, which to my amazement works. It seems very
strange to me that you build up this *string* of the expression you
want to access, and pass it to the Color constructor. It's as if
the Color constructor, upon recognizing it as a string, calls
eval() on it. But also I don't see how this could work while the
version in mySetColorVersion1 fails.
function mySetColorVersion2( t:String, a:String, c:String )
var color = new Color( "holder_mc.subholder_mc." + t +
".specific_mc." + a );
color.setRGB( c ); // it works -- but how, why ?!?!
I also tried the experiment in mySetColorVersion3, where I
built up a string again, but this time used the [ ] notation for
one of my variable movie clip accesses. This doesn't work.
function mySetColorVersion3( t:String, a:String, c:String )
var color:Color = new Color( "holder_mc.subholder_mc[ " + t
+ " ].specific_mc." + a );
color.setRGB( c ); // also does nothing
So it only works when I build up the access as a string, and
when I use only the "." notation in that string, as in
mySetColorVersion2. Can anyone explain to me what is going on here.
Shouldn't my direct access of the movie clip work if the string
version works? Shouldn't my string version with the brackets work
if the dot version works? I've used Color() and setRGB() plenty of
times with simple movie clip parameters, but for some reason in
this case where I have this complicated chain of property accesses,
it only works with this strange string version.