Skip navigation
Currently Being Moderated

how to enforce a function signature?

Mar 10, 2012 11:14 AM

Hi,

 

I hava a class structure like this

 

class B {

  var func:Function;

}

class A {

   var b:B;

}

class A1 extends A {

   function A1() {

       super();

       b.func = myfunc;

   }

   function myfunc(var onoff:Boolean) {

   }

}

 

and somewhere an event handler like this

 

function hndl(e:Event):void {

   if(e.target is A && A(e.target).b.func != null)

      A(e.target).b.func(something)

}

 

So if one of the A variants wants to implement the function, it lives in its own namespace. Now, how could I ensure that the compiler checks the argument structure?

 
Replies
  • Currently Being Moderated
    Mar 10, 2012 12:15 PM   in reply to birnerseff

    Are you talking about method overloading (not supported) or type checking (as3 is still not strong typed)?

     

    As much as you can do to help yourself is expose a public property to check what version you're running. typeof typically will always return object which isn't useful at all.

     

    This post may help with the methods mentioned.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2012 12:45 PM   in reply to birnerseff

    Yes, method overloading (supplying the same function name with an optional number of arguments) is not supported.

     

    AS3 will get there but for now you're better off doing one of two things.

     

    1, including all possible methods with a default value possible

    e.g. private function methodName(a:int = 0; b:String = '', c:CustomClass = CustomClass(), yada...)

     

    2, changing the function name for the arguments you need

    e.g. private function methodThatAcceptsFourArguments(a:int = 1, b:int =2, c:int = 3, d:int = 4)

     

    There is nothing in between without method overloading.

     

    Note AS4 has namespaces, overloading, etc....

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points