Does anyone know a method to dynamically index an arbitrarily deep array
or object-literal?

e.g. Given an object "t", and the string "one.two", how can you access
t.one.two?

Here is some sample code to demonstrate the problem:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical">
     <mx:Script>
         <![CDATA[
             public function f():void {
                 var t:Object = new Object();
                 t.one = [];
                 t.one.two = "content";

                 // Works:
                 output1.text = t["one"]["two"];

                 // Now what?
                 var indices:String = "one.two";

                 var tmp:String = "";
                 for each (var item:String in indices.split(".")) {
                     tmp += "[" + item + "]";
                 }

                 output2.text = t + tmp;

             }
         ]]>
     </mx:Script>
     <mx:Text text="test" id="output1" creationComplete="{f()}" />
     <mx:Text text="test" id="output2" />
</mx:Application>

Any help would be greatly appreciated.

Thanks!
Keith

Reply via email to