5 Replies Latest reply on Oct 20, 2010 5:59 AM by BhaskerChari

    Call to a function from other Class

    RaúlKirm

      Hi!, I have a Flex proyect with this code, inside the package "paquete":

      <?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"
                     backgroundColor="black"
                     creationComplete="init();callLater(showInitTime);" currentState="Inicial"
                     frameRate="24" preloader="paquete.CustomPreloader" >
      ...
      <fx:Script source="Principal.as" />
      ...
      

       

       

      "Principal.as" file has this function:

      public function loquesea():void{
           ...
      }
      

       

      And, for the preloader I have this class:

      package paquete
      {   
          imports ...
          
          public final class CustomPreloader extends DownloadProgressBar
          {
             
              public function CustomPreloader() 
              {
                  
                 //HOW I CALL FROM HERE loquesea() FUNCTION in Principal.as ????
                  super(); 
              }
      
      

       

      well, my question is inside the above code

       

      THANKS!

        • 1. Re: Call to a function from other Class
          BhaskerChari Level 4

          Well create an instance of  Principal class and call the loquesea() function of that class..

           

          public function CustomPreloader()
                  {
                     super();

                     var principalObj:Principal = new Principal();

                     principalObj.loquesea()
                  }

           

          Thanks,

          Bhasker

          • 2. Re: Call to a function from other Class
            RaúlKirm Level 1

            thanks for your fast answer, but it dont works, because "Principal.as" is not a class, is only a script added to the mxml with:

             

            <fx:Script source="Principal.as" />

            • 3. Re: Call to a function from other Class
              BhaskerChari Level 4

              Hi RaúlKirm,

               

              If you have included this script in your main mxml file(mind you not in another mxml component) you can call that function using the toplevel class as shown

               

              FlexGlobals.topLevelApplication.loquesea();

               

              Also dont forgtet to import the corresponding namespace for that...

               

               

              Thanks,

              Bhasker

              • 4. Re: Call to a function from other Class (AMF)
                RaúlKirm Level 1

                perfect, thanks!

                 

                Really, what I want to do is to call an AMF service (asking a text file) during the preload of my App.

                 

                The request to amf service after my app has started works fine, and the preload I added too works fine. My app has a preload of 3000ms, and my idea is that in that time of the preload, also download the data of the amf, and display data when my app is completely loaded, is that possible???

                 

                I have this code in my mxml:

                 

                    <mx:RemoteObject  id="amf"  source="test"   destination="amfphp">
                            <mx:method name="recibe" result="amfResult(event);"  fault="amfFault(event);"/>  
                        </mx:RemoteObject>  
                

                 

                 

                and this function in my "Princiapal.as":

                 

                private function amfEnviar():void{    
                    amf.recibe.send(""); 
                } 
                
                • 5. Re: Call to a function from other Class (AMF)
                  BhaskerChari Level 4

                  Yes I think you can do it..Have you tried with that...??

                   

                   

                  Thanks,

                  Bhasker