3 Replies Latest reply on Jun 10, 2009 2:53 PM by KomputerMan.com

    Dynamically Create Associative Arrays

    KomputerMan.com Level 1





      This should be pretty simple... really...  All I am doing is returning a result set from a query.  When I process the result set I want to create a unique Associative Array for each item returned.  I.E. One record might contain the word “MainMenu” so I want to create an Object called MainMenu that I will populate at a later time.  How do I do this??? 


      Below is the code that gets called when the query set is returned to my app.  I first store the result set into a datamodel, then I want to create a new Object.   Thanks in advance for your assistance!!!



      private function GetFuncTypesHandler(event:ResultEvent):void{

           model.funcTypes = new ArrayCollection(event.result as Array);


           for(i = 0; i < model.funcTypes.length; i++){



               var model.funcTypes[i].sec_func_type.toString():Object = new Object(); // PLEASE HELP HERE!!!





      Have an Ordinary Day...

      Kurtis   ~|:-)


        • 1. Re: Dynamically Create Associative Arrays
          BennyBeta Level 4

          I'm not sure I understand, but maybe try:


          var map:Object = new Object();


          ... (inside of loop)

          map[ model.funcTypes[i].sec_func_type.toString() ] = new Object();

          • 2. Re: Dynamically Create Associative Arrays
            leybniz Level 4

            Have you ever considered to use Dictionary class for having something associative in Flex?

            1 person found this helpful
            • 3. Re: Dynamically Create Associative Arrays
              KomputerMan.com Level 1


              Maybe it would help if I explain what I want. Basically I am building a granular security scheme for my latest application.


              To implement the security scheme I have in mind I need to store multiple key value pairs in multiple security relates objects (SRO).  You can think of a SRO like you would a structure in Cold Fusion.  I need to pass in the name of my SRO at runtime because I want my security requirements configurable.  Right now I am passing in three values from my database table.  They are "MainMenu", "SubMenu", and "WorkSpace".


              When the end user logs into the application the authentication routine will write the key value pairs associated to that account to the SRO.  I.E.  The MainMenu object might get a key of "Administration" and a value of "R".  Another entry in the MainMenu object could be "Reports", "M". 


              When the end user calls a function within the application it will check security to see if the end user is authorized to use that applet.  The check will be something like testing to see if SRO "MainMenu" has a key called "Administration", if yes what is the value.  If no the function can not be used by the end user.  I am leaving out a few details as you can imagine but I am also sure you get the idea.


              Thanks again for the assistance...

              Kurtis   ~|:-)



              O.K. so I looked at the Dictionary a little closer and it will work fine... So I just modified my code to look like this:







              public var mySecRights:Dictionary = new





              private function GetFuncTypesHandler(event:ResultEvent):



              model.funcTypes =


              new ArrayCollection(event.result as





              i:int = 0; i < model.funcTypes.length; i++){



              Now I can pass in all of my top level security names to the dictionary and I will be happy.  Thanks for all of your insights!!!