1 Reply Latest reply on Sep 12, 2006 8:34 AM by Prpl_Ppl_Etr

    Function calling problem

    srib
      Hi,

      I created a class file and in constructor loading a XML file and on Load of XML I am calling different function with in the same class, but it is not executing can you please tell me where is the problem.
      Here is the code given below.


      class myClass
      {
      private var myXML:XML;
      public function myClass()
      {
      myXML.load("myXML")
      myXML.onLoad = function()
      {
      displaText() // This is the function which is not calling
      }
      }

      public function displaText()
      {
      trace("Welcome")
      }
      }
        • 1. Function calling problem
          Prpl_Ppl_Etr
          It looks like you've got a scoping issue...

          try:

          var pointer:myClass=this;
          myXML.onLoad=function(success){
          if(success){
          pointer.displaText();
          }else{
          // error handling
          }
          }

          When you call a function within an onLoad event, that function is scoped to the object being loaded. If you want to call a method from another object (in this case from your 'myClass' class), you need to use a reference to the object that contains the function.

          Don't forget to use the new XML constructor when instantiating your XML object:
          myXML= new XML();

          Also... it's a best practices thing... you should capitalize your class names (MyClass instead of myClass). You'd then likely use the lower case (myClass) to name an instance of the class.

          Cheers,
          PPE