# Flash EventDispatcher question

**URL:** <https://forum.kirupa.com/t/flash-eventdispatcher-question/192062>\
**Category:** Uncategorized\
**Created:** [June 25, 2006, 6:53pm UTC](https://forum.kirupa.com/t/flash-eventdispatcher-question/192062 "2006-06-25T18:53:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hickscorp](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hickscorp](https://forum.kirupa.com/u/hickscorp)\
**Post date:** [June 25, 2006, 6:53pm UTC](https://forum.kirupa.com/t/flash-eventdispatcher-question/192062/1 "2006-06-25T18:53:51Z")

</div>

Hello people here,

I’m new here, so maybe i’m posting in the wrong channel. Please tell me if it is the case…

I’m trying to get a simple client socket class to work with events.  
I have tried each example found with google with no luck, i just tried the “radio listeners” example from here, which worked fine until i put the broadcaster object within my class…

Main code:

```auto

import mx.events.EventDispatcher;

// A listener object for server events.
this.srvListener = new Object();
this.srvListener.onSrvConnect = function(eObject:Object):Void {
    trace("From Listener: onConnect()");
};

// Instanciate the main client socket class.
var cMainCon:CServerConnexion = CServerConnexion.GetInstance();
// Add the main listener object to it...
this.cMainCon.cBroadcaster.addEventListener("onSrvConnect", this.srvListener);
// Let's connect now.
this.cMainCon.Connect("localhost", 8081);

```

Class code:

```auto

import mx.events.EventDispatcher;

class CServerConnexion {
    
    // The Singleton instance.
    private static var cInstance :CServerConnexion;
    // The main socket.
    private var cMainSock :XMLSocket;
    public var cBroadcaster :Object;
    
    // Main Constructor.
    private function CServerConnexion() {
        // Set up this class to be event aware.
        this.cBroadcaster = new Object();
        EventDispatcher.initialize(this.cBroadcaster);
        
        // Instanciate the main server socket.
        this.cMainSock = new XMLSocket();
        // Use those events handlers on connexion.
        this.cMainSock.onConnect = this.onConnect;
        this.cMainSock.onXML = this.onXML;
        this.cMainSock.onClose = this.onClose;
    }
    
    // Connects to the server.
    public function Connect(szHost:String, iPort:Number) {
        this.cMainSock.connect(szHost, iPort);
    }
    
    // Event handler, on connection.
    public function onConnect(bSuccess:Boolean) {
        trace("From Main class: onConnect()");
        this.cBroadcaster.dispatchEvent({type:"onSrvConnect"});
    }
    public function onXML(szData:XML) {}
    public function onClose() {}
    
    public static function GetInstance():CServerConnexion {
        if (CServerConnexion.cInstance==undefined)
            CServerConnexion.cInstance = new CServerConnexion();
        return CServerConnexion.cInstance;
    }
}

```

When i start the flash, i only get the class message (“From Main class: onConnect()”)…  
Any kind of help (Clues, links, incomplete sentenses :te:) greatly appreciated. Thanks

Kind regards,  
Pierre
