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

Reply via email to