2 Replies Latest reply on Jan 3, 2007 1:38 PM by ntsiii

    Writing Static Method.

    Camus Miu Level 1
      Hi, I have a class which loads XML and store as variable, which is for text used in binding to Flex label display.

      [Bindable]
      public class GetXmlResources
      {
      public var xmlContent:XML;

      public function GetXmlResources(){}

      public function initXml(xmlURL:String):void
      {
      var loader:URLLoader = new URLLoader();
      loader.dataFormat = "text";
      loader.addEventListener( Event.COMPLETE, handleComplete );
      loader.load( new URLRequest( xmlURL ) );
      }

      private function handleComplete( event:Event ):void {
      try {
      // Convert the downlaoded text into an XML instance
      var example:XML = new XML( event.target.data );
      // At this point, example is ready to be used with E4X
      //trace( example );
      this.xmlContent = example;
      } catch ( e:TypeError ) {
      // If we get here, that means the downloaded text could
      // not be converted into an XML instance, probably because
      // it is not formatted correctly.
      trace( "Could not parse text into XML" );
      trace( e.message );
      }
      }
      }

      Application as following (in MXML):

      [Bindable]
      public var tmp:GetXmlResources;

      this.tmp = new GetXmlResources();
      this.tmp.initXml("resources/xml/text_reference.xml");

      <mx:Label x="10" y="4" text="{tmp.xmlContent.Layout.ProductFilterFind}"/>

      =====================================================

      Now I want to make the instance laoding "resources/xml/text_reference.xml" as a Singleton Class...

      like making a class named LayoutText extends GetXmlResources
      and in the contstructor of GetXmlResources, load the "resources/xml/text_reference.xml"

      so I can use as following
      <mx:Label x="10" y="4" text="{LayoutText._xml.Layout.ProductFilterFind}"/>

      but seems no luck... can anyone help me?