A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: can I have multiple constructors?

  1. #1
    Junior Member
    Join Date
    May 2002
    Posts
    10
    I've dabled in Java and c++, both allow for multiple constructor functions. I'm trying to create a class in MX with multiple constructor functions using the same principles but it doesn't seem to be working. Does anyone know if MX supports multiple constructor functions? The following is the scripting you would use in C++, and is what I tried using in MX:

    function myClass(){
    this.a = "";
    this.b = "";
    }

    function myClass( A ){
    this.a = A;
    this.b = "";
    }

    function myClass( A,B ){
    this.a = A;
    this.b = B;
    }

  2. #2
    Sleepy
    Join Date
    Apr 2001
    Location
    Tallahassee, FL
    Posts
    498
    it's called overloading, and yes I believe that you can overload functions in MX so long as each function is unique (in parameters). your example should be fine. However, the following would not. Note, I am assuming that the functions are declared in the same scope...

    function testme(){
    }

    function testme(){
    }

    this would not work


    HTH, and have a happy 4th!

  3. #3
    Junior Member
    Join Date
    May 2002
    Posts
    10

    RE:RE

    If you look at the script example, my functions are unique (in parameters). However, MX refuses to call the appropriate constructor when instanciating the objects.

  4. #4
    Sleepy
    Join Date
    Apr 2001
    Location
    Tallahassee, FL
    Posts
    498

    hmm....

    you're absolutely right. I apologize for that. When I responded I had not actually tried it in flash. I responded with an "off the top of my head" answer. It does seem strange that flash would not allow overloading. If I come up with a way to do it I will certainly let you know


    Happy 4th!

  5. #5
    Junior Member
    Join Date
    May 2002
    Posts
    10
    thanks

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