12 Replies Latest reply on Oct 29, 2010 3:28 AM by TheGarfunkal

    Call to a possibly undefined method....

    TheGarfunkal

      Hiya

       

      So I expect the 'Call to a possibly undefined method' one is familiar, and you are all groaning...

       

      sorry

       

      I have an MXML file and I want it to be able to call a function in an actionscript file, but I get the error.

       

      I've tried a number of ways to import, inlcude and so on the AS file, with no success.  I'm trying to call CurrentAvailability() which is in the actionscript.

       

      I noticed when I added the sql.as and MSsql.as that they werent in the type ahead intelisense thingy, but the Pod and PodContentBase where. 

       

      Where am I going wrong!

       

       

      Main Mxml: (obviously cut down!)

       

       

      import dashboard.view.ActionScript.Pod;

      import dashboard.view.ActionScript.PodContentBase;

      import dashboard.view.ActionScript.sql;

      import dashboard.view.ActionScript.MSsql;

       

      [Bindable]

      public static var ChosenSystem:String="AIS MI";

       

      public function changeEvt(event:Event):void

      {

      ChosenSystem = event.currentTarget.selectedItem;

      // CurrentAvailability();

           {CurrentAvailability()};

       

      sql.AS

       


      import mx.events.ListEvent;

      import mx.controls.Alert;

       

      public function CurrentAvailability():void {

       

         mssqlQuery("SELECT * FROM [MI_Specialists].[dbo].[Portal_SystemStatus] WHERE [Application] =  '" +  CMIPortal.ChosenSystem   + "' AND  ID in ( SELECT MAX([Id]) [Application] FROM  [MI_Specialists].[dbo].[Portal_SystemStatus] group by [Application]) ","CurrentAvailability");

      /

        }

        • 1. Re: Call to a possibly undefined method....
          Devtron Level 3

          Do you have a class or package name in your SQL.as file?

           

          That is what you need to reference the function.

          • 2. Re: Call to a possibly undefined method....
            TheGarfunkal Level 1

            Hi - Thanks for the help

             

            so, I tried to give it a package or a class,  and the error was 'packages (or classes) cannot be nested'

             

            There are a number of other Functions in the as, which i;ve removed - but they all do a similar thing.

            // ActionScript file

             

            package dashboard.view.ActionScript

            {

            import mx.events.ListEvent;

            import mx.controls.Alert;

             

             

            public class Sql

            {

             

            private function CurrentAvailability():void {

             

               mssqlQuery("SELECT * FROM [MI_Specialists].[dbo].[Portal_SystemStatus] WHERE [Application] =  '" +  CMIPortal.ChosenSystem   + "' AND  ID in ( SELECT MAX([Id]) [Application] FROM  [MI_Specialists].[dbo].[Portal_SystemStatus] group by [Application]) ","CurrentAvailability");

             

              }

             

             

            }

            }

             

             

             

            • 3. Re: Call to a possibly undefined method....
              TheGarfunkal Level 1

              Any ideas anyone? I'm well stuck!

              • 4. Re: Call to a possibly undefined method....
                Devtron Level 3

                I noticed that your function does not produce a result, or return anything. Is that true?


                • 5. Re: Call to a possibly undefined method....
                  TheGarfunkal Level 1

                  Yes thats right. It ends up writing info to an event.result down the

                  line. The function works fine. I just can't call it!

                   

                  I can call the function from a different mxml, but not the main application.

                  • 6. Re: Call to a possibly undefined method....
                    Devtron Level 3

                    Well that's very strange. Do you import the namespace for the class, at the top of your Application MXML?

                     

                    You may need to create an instance of the SQL class (an object) and call the function through your new object.

                    • 7. Re: Call to a possibly undefined method....
                      TheGarfunkal Level 1

                      Yeah. I do this at the top of the application:

                       

                      *

                       

                      import dashboard.view.ActionScript.Pod;

                       

                      import dashboard.view.ActionScript.PodContentBase;

                       

                      import dashboard.view.ActionScript.sql;

                       

                      import dashboard.view.ActionScript.MSsql;

                       

                      What do you mean create an instance of the class?  Sorry - bit new to

                      flex/AS.

                       

                      I don't have a package/class defined in the .as. I tried but it companies of

                      nesting classes.

                      *

                      • 8. Re: Call to a possibly undefined method....
                        Evtim Georgiev (Adobe) Level 2

                        Hi Andrew,

                         

                        I think you can put all of your functions in a class and make them static. This way you can access them without the need to create a class instance. Here's how it looks:

                         

                        In a folder "myPackage", I created a file "Functions.as" - the class name must be the same name as the file name:

                         

                        package myPackage
                        {
                            public class Functions
                            {
                                public static function hello():void
                                {
                                    trace("Hello");
                                }
                               
                                public static function heyThere():void
                                {
                                    trace("Hey there");
                                }
                            }
                        }

                         

                        In my main app, I call the functions like this:

                         

                        <?xml version="1.0" encoding="utf-8"?>
                        <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                                       xmlns:s="library://ns.adobe.com/flex/spark"
                                       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="application1_initializeHandler(event)">
                            <fx:Declarations>
                                <!-- Place non-visual elements (e.g., services, value objects) here -->
                            </fx:Declarations>
                           
                            <fx:Script>
                                <![CDATA[
                                    import mx.events.FlexEvent;

                         

                                    import myPackage.Functions;

                         

                                    protected function application1_initializeHandler(event:FlexEvent):void
                                    {
                                        Functions.hello();
                                        Functions.heyThere();
                                    }

                         

                                ]]>
                            </fx:Script>
                        </s:Application>

                         

                        Hope this helps,

                        -Evtim

                        • 9. Re: Call to a possibly undefined method....
                          TheGarfunkal Level 1

                          Hi - thanks so much.

                          So I guess in my code if I make my SQL.as a package called by the same

                          name as the folder it's in, and then make my functions static and

                          within a defined class name, then I'll be ok? I won't get the nested

                          errors?  I'll give it a whirl first thing. Many thanks.

                          • 10. Re: Call to a possibly undefined method....
                            TheGarfunkal Level 1

                            Hi

                             

                            I still get Packages cannot be nested errors.

                             

                            The main mxml file has pods which are classes that extend vbox - I suppose these pods then call the actionscript package and this is the problem.

                             

                            Is there anyway around it? 

                             

                            Basically I have an mxml file - In it is a combobox and this combobox creates a static variable that is used in a query sent via asp.net to a sqlserver db.

                            When the user first accesses the app  the variable defaults to a value - the pod (the class that extends vbox - there are multiple pods in the main mxml file) then on creationcomplete fires the sql.as to get its data and return it to the screen.  I need to be able to allow the user to change the combobox, and refire the query and get the new data.

                             

                            I have in the main mxml file an event that fires wen its changed and now what I am trying to do is to make it fire the function in the sql.as at this point - this is what i cant do.  I cant fire it fine from the pod class.  If i put a button in there that when clicked triggers it, but it needs to be based on the combobox so that ALL the pods are refreshed based on this one variable.

                             

                            Sorry if this seems a bit muddled - i'm a bit in the deep end!

                            • 11. Re: Call to a possibly undefined method....
                              TheGarfunkal Level 1

                              is there a clean way to re initiate the creation of these pods - the class -  when the combobox is changed?

                               

                              like  a refresh - although i know refresh isnt the correct term!

                              • 12. Re: Call to a possibly undefined method....
                                TheGarfunkal Level 1

                                Hi

                                Can anyone help? I'm freaking out now (not really but you get the picture).

                                 

                                The problem seems to be that the main MXML has these Pods that operate within it. The pods are based on an actionscript class.  Within the pods i need to get some data, and I've done that via other actionscript files which arent  defined as packages and classes.   When I do define them as such, I get the 'you cant nest packages' error.  This will also cause issues for me if I create a renderer in AS as I cant 'nest' that either!

                                 

                                I assume I need to move stuff about, but Im very new to flex and I'm floundering in the dark a bit, so I apologise if this is all a bit vauge

                                 

                                Bit of trauma!

                                 

                                Any ideas?