7 Replies Latest reply on Oct 3, 2006 7:42 AM by spotsstang

    Data Management help

    spotsstang
      We have a large application in development that has a lot of lateral sibling pages that require the use of the same variables. We are looking for a way to achieve this other than making a function call repeatedly. Below is how we are currently doing it but I am sure there is a much better method. What we would like to do is have a global object available that we can store variables in and grab when needed. Any suggestions would be greatly appreciated.

      1. CompanyManagement.mxml
      function goToLocations()
      we set a TextEvent and pass it a CompanyId; but would like
      to pass an object containing all of the properties of the selected Company
      2. ResourceCoverage.mxml
      the event listener for "editLocations"

      function editCompanyLocations()
      we set a public variable [selectedCompanyId] with the selected property from the TextEvent then pass the newly set selectedCompanyId to a property on CompanyLocationManagement.mxml also called selectedCompanyId

      Step 1:
      private function goToLocations():void {
      //selectedCompany = dgCompanies.selectedItem as Company;

      var id:int = dgCompanies.selectedItem.CompanyID;
      var editLocationsEvent:TextEvent = new TextEvent("editLocations",true);
      editLocationsEvent.text = id.toString();
      dispatchEvent(editLocationsEvent);
      }


      Step 2:
      private function initApp():void {
      selectedCompanyId = 0;
      selectedCompanyLocationId = 0;

      addEventListener("editLocations",editCompanyLocations);
      addEventListener("editMapCoverage",editMapCov);
      }

      private function editCompanyLocations(x:TextEvent):void {
      selectedCompanyId = Number(x.text);
      tabResource.selectedIndex = 1;
      }


      <mx:Canvas label="Locations" width="100%" height="100%" id="tabLocations">
      <views:CompanyLocationManagement selectedCompanyId="{selectedCompanyId}" enabled="false"/>
      </mx:Canvas>
        • 1. Re: Data Management help
          inlineblue Level 1
          If you want a global data structure, then I suggest creating a class with static properties to act as your global variables. Then you can get them like: MyStaticClass.var1
          • 2. Re: Data Management help
            spotsstang Level 1
            I will look into that. Thanks and if you have any other ideas please feel free to pass them along. i want to keep the global structure as clean as possible.
            • 3. Re: Data Management help
              ntsiii Level 3
              You might want to look into the Cairngorm architecture. It wes designed for making large Flex applications manageable.

              Tracy
              • 4. Re: Data Management help
                spotsstang Level 1
                Thanks ntsiii I will look into it.
                • 5. Re: Data Management help
                  spotsstang Level 1
                  quote:

                  Originally posted by: inlineblue
                  If you want a global data structure, then I suggest creating a class with static properties to act as your global variables. Then you can get them like: MyStaticClass.var1


                  I am a little fuzzy on creating a class to hold the variables. I would like to have a class that has a set of variables that are set to default values then updated when a event cause a new value to be present. For example at first a companyID is 0 but then a user enters their information and we do a look-up and return back the companyID. I then want to pass this ID to the class and set the variable to hold this new value. This will need to take place for multiple variables at different events. Could someone post a example of how I can achive this?
                  • 6. Re: Data Management help
                    inlineblue Level 1
                    Here's a simple example:

                    class MyGlobals
                    {
                    public static var companyID: int = 0;
                    pubilc static var companyName: String = "";
                    }

                    Import this class wherever you need access to these variables. Then in your event handlers (eg. when you receive user input), just set the variable you need:

                    MyGlobals.companyID = userinput;

                    Because the variables are static, there's only ever once instance of each. So somewhere else you can retrieve the company id:

                    myCompanyID = MyGlobals.companyID;
                    • 7. Re: Data Management help
                      spotsstang Level 1
                      Thanks for clearing that up for me inLineBlue!