3 Replies Latest reply on May 10, 2011 2:53 AM by dsdsdsdsd

    is applicationComplete required to call inline functions

    dsdsdsdsd Level 1

      hello; it seems that the only way I can call a function within a script tag is by waiting for the applicationComplete event ...                 

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application ...

                           applicationComplete = "om_initiate()"   // ... no problem

          >
          
           <fx:Script>
               <![CDATA[

       

                  public function om_initiate(): void 
                  { trace( "om_initiate" ) ;              
                  };

                  public function om_test(): void 
                   { trace( "om_test" ) ;
                   };

                  om_test() ; // ... generates an error
                  
               ]]>
           </fx:Script>
      </s:Application>

        • 1. Re: is applicationComplete required to call inline functions
          pauland Level 4

          applicationComplete is an event handler. MXML is a tag based implementation of a class. You can only call methods (functions) in classes and in MXML, you can declare the functions within a script tag and call them in response to events or via publicly exposed functions. ApplicationComplete is simply an event handler for the APPLICATION_COMPLETE event. This allows you to call a suitable handler for that event. You can call code in response to any event that the MXML class responds to or call any publicly exposed function.

           

          It's not just applicationComplete, but that is a good initialiser event for the application, because by then all components have been instantiated.

           

          [ Taking applicationComplete as an example.

           

          If you write applicationComplete = "onApplicationComplete(event)" , Flex will build a handler for the APPLICATION_COMPLETE event and put as the body of the handler, the code that you write in quotes :  onApplicationComplete(event) .

           

          Therefore the handler built by the compiler for the event now includes code you have written to call your own function to handle what you want to happen when the event occurs. That's how it works. ]

          • 2. Re: is applicationComplete required to call inline functions
            dsdsdsdsd Level 1

            I think I get it ... A and B are the same ???

             

            A

            <s:Application>

            <fx:Script>
                      <![CDATA[

             

                        public function om_test(): void 
                         { trace( "om_test" ) ;
                         };

             

                        om_test() ; // ... generates an error

             

                     ]]>

            </fx:Script>

            </s:Application>

             

             

             

             

            B

            public class my_Application

              {

                        public function om_test(): void 
                         { trace( "om_test" ) ;
                         };

             

                        om_test() ; // ... which would generate an error in oop

              }

            • 3. Re: is applicationComplete required to call inline functions
              pauland Level 4

              That's the general idea.