# Accessing Singleton Methods

**URL:** <https://forum.kirupa.com/t/accessing-singleton-methods/244419>\
**Category:** flash\
**Created:** [November 17, 2007, 7:54pm UTC](https://forum.kirupa.com/t/accessing-singleton-methods/244419 "2007-11-17T19:54:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![quietless](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quietless/32/3370_2.png) [@quietless](https://forum.kirupa.com/u/quietless)\
**Post date:** [November 17, 2007, 7:54pm UTC](https://forum.kirupa.com/t/accessing-singleton-methods/244419/1 "2007-11-17T19:54:44Z")

</div>

Hello,

I’m a bit new at OOP and am trying to implement a Singleton that parses some XML into an object to use throughout my application. It is my understanding that getInstance() returns a reference to the object returned by the constructor. How then can I access the public methods of the returned object once its been instantiated? Calling the Singleton’s public methods returns a type error saying they are possibly undefined. Furthermore I am trying to an register an eventListener to notify me when the Singleton is done parsing the XML so I can continue building my application when that data is ready.

Any help would be greatly appreciated.

Thanks!

[//CustomXmlParser.as](https://CustomXmlParser.as)

```auto

    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.net.URLLoader;
    import flash.net.URLRequest;

public class CustomXmlParser extends EventDispatcher{
        private static var ldr:URLLoader = new URLLoader();
        private static var instance:CustomXmlParser;
        private static var allowInstantiation:Boolean;
        private static const myString:String = 'hello';

        public function CustomXmlParser():void
        {
            if (!allowInstantiation){
                trace('Error: Instantiation failed: Use CustomXmlParser.getInstance() instead of new');
            } else{
                dispatchEvent(new Event("XML_COMPLETE"));
            }
        }
        
        public static function getInstance():CustomXmlParser
        {
            if (instance==null){
                allowInstantiation=true;
                instance = new CustomXmlParser();
                allowInstantiation=false;
            }
            return instance;
        }
        public static function getString():String
        {  
            return myString;
        }
    }
}

```

// ApplicationMain.as

```auto

    import flash.events.Event;
    import flash.display.MovieClip;

public class ApplicationMain extends MovieClip{

private static var temp:CustomXmlParser = CustomXmlParser.getInstance();

    public function ApplicationMain()
    {
        trace(temp) // traces([object CustomXmlParser])
        trace(CustomXmlParser.getString()); // traces 'hello'
        temp.getString(); // error, call to possibly undefined method
        temp.addEventListener('XML_COMPLETE', onXmlComplete);  
   // says addEventListener method is unknown        
    }
    private function onXmlComplete(evt:Event)
    {
        trace('ready to move on');
    }
}

```
