3 Replies Latest reply on Jul 27, 2006 8:11 PM by gradez28

    Trouble accessing class from within components...

    gradez28
      I just started playing with flex 2 last night and im pretty happy with it so far, except im having a problem accessing top-level variables and classes from within custom components.

      I have a component, manageTickets that is included in the primary file Support.mxml

      In Support.mxml I have a class setup like this:

      import myClasses.mySites;
      public var mysite:Object = new mySites();

      Now, whenever i try to access this class from within my custom component, it throws the following error:
      "1119: Access of possibly undefined property mysite through a reference with static type Class."

      I have tried accessing it like this (and a few other ways with no luck)
      Support.mysite.hello();
      root.mysite.hello();


      I also have this problem whenever i set a public variable in the main file, and try to access it from the component.

      Thanks for any help!
        • 1. Re: Trouble accessing class from within components...
          Rebecca_Hyatt_-Adobe
          Well,
          Support.mysite.hello()
          would only work if mysite were a static variable of Support, which would be defined something like this...
          static public var mysite:Object = new mySites();

          If Support is the application file, and you want to set a (non-static) property on it from a component, I believe you want
          Application.application.mysite.hello();

          I'd also recommend typing mysite as a mySites object, rather than a generic Object...
          public var mysite:mySites = new mySites()
          That'll let the compiler really know what it is and what members it has.

          Rebecca Hyatt
          Adobe
          • 2. Re: Trouble accessing class from within components...
            doug777 Level 1
            You have to pass a reference to the file you want to access:

            import myClasses.mySites;
            public var mysite:Object = new mySites(this);

            Then in the class file:

            private var support:Support;

            public function mySites(s:Support){
            support = s;
            }

            Then in the functions you can refer to variables in the Support file as support.varName

            You can adapt this to work to talk to variables (as long as they're public) anywhere you want.

            Doug
            • 3. Re: Trouble accessing class from within components...
              gradez28 Level 1
              Setting the class to static worked, thanks. But, what kind of limitations will I face with the class being static?

              Also, I had previously tried the Application.application.mysite.hello(); and the following error results:
              1120: Access of undefined property Application.

              Thanks for the help!