A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: overriding base class methods while calling original methods

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349

    overriding base class methods while calling original methods

    I would like to write a class that extends XMLSocket. I'd like to call my class RPCSocket. Among other things, I want to add a property which indicates that the socket is 'waiting to connect'. This would mean that the connect() method of XMLSocket has been called but the CONNECT event has not yet been dispatched. I'll therefore need to override the CONNECT and CLOSE methods of XMLSocket in my class, RPCSocket.

    I haven't yet seen any reason why I can't override these methods -- they are neither constant nor static nor final and do not implement an interface method (as far as I can tell) and they are inherited.

    I obviously need to call the original connect() and close() methods of the XMLSocket, however. Is this code the proper way to do this? Can anyone see any particular problem with this?

    code:

    package {
    class RPCSocket extends XMLSocket {
    public var boolWaitingToConnect:Boolean = false;

    public override function connect(host:String, port:int):void {
    boolWaitingToConnect = true;
    super.connect(host, port);
    }
    public override function close(host:String, port:int):void {
    boolWaitingToConnect = false;
    super.close();
    }
    }
    }

    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, did you try it? I don't see any reason off the top of my head that that would not work. Though passing the host and port to the close method is a little weird.

  3. #3
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    I gooofed...no params for the close method.

    I haven't tried it yet...still trying to get access to a server supporting sockets. I was just wondering if the approach might work or was totally stupid before writing up the entire class.

    new code (without close params).

    code:

    package {
    class RPCSocket extends XMLSocket {
    public var boolWaitingToConnect:Boolean = false;
    public override function connect(host:String, port:int):void {
    boolWaitingToConnect = true;
    super.connect(host, port);
    }
    public override function close():void {
    boolWaitingToConnect = false;
    super.close();
    }
    }
    }



    PS: Webmaster here should work on code to format actionscript...it adds extra line breaks and there's no color coding!
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    For formatting, use the [ code ] tag or [ php ] tag instead of the [ as ] tag.

    One other thing about your code above. The boolWaitingToConnect var will be true from the time connection is attempted until close is called. Clearly, it's only actually waiting until the connect happens. You may want to add a CONNECT listener event handler to your class to set the var to false when the actual connection happens.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center