1 Reply Latest reply on Mar 11, 2008 5:50 AM by JKohn99

    Better way to process loops in ActionScipt

    KomputerMan.com Level 1
      I have two ArrayCollections in my application. One of them is called functions2Security and the other is called userSecurity. A sample of the data contained in these collections is shown below:

      functions2Security[0].FunctionName = "Administration_Menu"
      functions2Security[0].SecCnt= 1
      functions2Security[1].FunctionName = "Report_Menu"
      functions2Security[1].SecCnt= 2
      functions2Security[2].FunctionName = "Project_Menu"
      functions2Security[2].SecCnt= 3

      userSecurity[0].SecCnt = 1

      What I want to do is make sure that the userSecurity ArrayCollection contains the same secCnt as the functions2Security collection to turn on or hide a navigation tab in the application. Or in other words this is my security scheme. I have the following code that will verify that the values match but I am thinking there has to be a better way. Here is what I have but am looking for advice on ways to make this more efficient.

      var i:int = 0;
      var x:int = 0;
      var showReportMenu:int = 0;

      for(i = 0; i < model.functions2Security.length; i++){
      if(model.functions2Security .FunctionName == "Report_Menu"){
      if(showReportMenu == 1){
      for(x = 0; x < model.userSecurity.length; x++){
      .SecCnt == model.userSecurity[x].SecCnt){
      showReportMenu = 1;

      Thanks in advance for your suggestions!!!

      Have an Ordinary Day...
      KomputerMan ~|:-)
        • 1. Re: Better way to process loops in ActionScipt
          JKohn99 Level 1
          Make hash tables instead. You can find some on the net
          or just make your own. Class Object can be used just like a hash table:

          var myHash:Object = new Object();

          var myKey:String = "report_menu";
          var someObject:MySecClass = new MySecClass();
          someObject.functionName = "report_menu";
          someObject.SecCnt = 1;
          myHash[myKey] = someObject;

          Now you can get access to someObject
          by using it's key:

          var someObject:MySecClass = myHash["report_menu"];

          We use this approach for all labels and messages and it is much
          faster then iterating arrays.