One dirty way would be like this:
var sTarget:String = "first.second.third.fourth";
var aTarget:Array = sTarget.split(".");
var mcTarget = this[ aTarget[0] ];
for (var i:int = 1; i < aTarget.length; i += 1)
{
mcTarget = mcTarget[ aTarget[i] ];
}
trace( mcTarget );
/ Viktor H
On Thu, 12 Jun 2008 10:44:34 +0200, Ali Drongo <[EMAIL PROTECTED]>
wrote:
Hmmm, can anyone suggest the completed code? I can't see how this would
work as you are returning a class reference that is named after the root
object. Maybe I am missing something.
Any suggestions much appreciated to keep me out of a long-hand switch
statement :)
Ali
On 12 Jun 2008, at 04:48, Kerry Thompson wrote:
Ali Drongo wrote:
Hello, I'm being passed a string that has a reference to an object in
dot-syntax like this: "myOb.property.property2.property3"
The object targeted may be a varying number of levels inside of the
top-level object.
I have tried to write this by turning the string into an array and
then creating the object but I'm not sure how:
public static function arToObj(a:Array):Object
{
var retObj:Object;
for ( var i:Number=0; i<a.length; i++ ) {
if (i==a.length-1){
//dont know what to do here !!
}
};
return retObj;
}
This is untested e-mail ActionScript, but you could do something like
this:
public static function arToObj(a:String):Object
{
var strArray:Array;
var clsRef:Class;
strArray = a.split(".");
clsRef = getDefinitionByName(strArray[0]) as Class;
return new clsRef();
}
I'm sure there are bugs in there, but that's the basic approach I'd
take.
Cordially,
Kerry Thompson
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders