4 Replies Latest reply on Feb 11, 2010 2:34 PM by CrazyMerlin

    Package/Class name resolution issue

    CrazyMerlin Level 1

      Hey guys!

       

      I have an application called Infused. I also have a package called Managers with a class called DataManager which extends HTTPService.

      In a function in DataManager I need to call a public function that exists in Infused.

       

      Now, if the application is called Infused, then it's default class must be called Infused too, right?

       

      But when I called Infused.loginResult(evt) I get the error: Access of possibly undefined method loginResult through a reference with static type Class.

       

      I assumed the applications class would be in the global namespace and accessible. Am I wrong? And if so how can I call the function?

       

      Also, in the applications main class I have a number of functions called xxxResult which I need to call depending on a string that is passed in to the class request function. So the request function may receive 'login', and so the function to call in Infused would be 'loginResult'.

       

      How can I call the function based on this string? I know I could do Class[functionName]() if the function where in the same class, but will the answe to my first question lead to the obvious solution for the second?

       

      I am a PHP5 OOP developer learning Flex, so please forgive my dumbassness

       

      Thanks for any help.

      Paul.

        • 1. Re: Package/Class name resolution issue
          msakrejda Level 4
          But when I called Infused.loginResult(evt) I get the error: Access of possibly undefined method loginResult through a reference with static type Class.

          You can't call instance methods like that. You'd need to make the method static, or alternately, call Infused(Application.application).loginResult(evt). After you make either change, you should be able to use the ['functionName']() approach.

           

          Keep in mind, though, that you're coupling your DataManager to your application with this approach. This might be fine for a small app, but take a look at Mate (or some of the other MVC frameworks) to see how to reduce or avoid this sort of coupling.

          1 person found this helpful
          • 2. Re: Package/Class name resolution issue
            CrazyMerlin Level 1

            The initial app was built around a thought process as I am just learning AS3 in Flex, and is quite small. I will make sure to MVC the final app once I have a better understanding of the approaches to this in AS3.

             

            However, what you suggested doesn't seem to work. If I make the method static, then I cannot reference the MXML components. If I tru to call Infused(Application.application).loginResult() I get a "Access of undefined property Application" error.

             

            Any thoughts?

            • 3. Re: Package/Class name resolution issue
              msakrejda Level 4

              If your handlers are referencing components within the app, you're right--static is not an option. The other approach should work, though. Perhaps you need to import mx.core.Application?

              • 4. Re: Package/Class name resolution issue
                CrazyMerlin Level 1

                Ah finally, I can separate my data logic!

                 

                Thanks man, I had imported mx.core.Application

                 

                << a contented developer!