If you fell developing it, I wrote an experiment about the flash proxy
class. I would do it that way. The proxy class makes you able to handle new
methods and properties on any other classes (especially the one that are not
dynamic, almost all of them), to access to something like:

mySprite.myNewProperty
mySprite.myNewMethod

In my example I proxy an array but you could do it for anything.

http://www.soundstep.com/blog/2008/05/27/data-access-with-array-extending-an
d-proxy-extending/

Make a search on Google with the keywords as3, proxy and dot syntax maybe
someone has already done that.

Hope it helps.

Romu


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Viktor
Hesselbom
Sent: 12 June 2008 10:01
To: Flash Coders List
Subject: Re: [Flashcoders] AS3: How can I target an object from
adot-sytaxstring?

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
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to