Flex – In ActionScript, there is no way to test whether the data type “function” exists

So I have a class and I instantiate a variable callback as follows:

public var callback:Function ;

So far so good. Now, I want to add an event listener to this class and test whether there is a callback. I do this:

this.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent): void {
if (callback) {
// do some things
}
});

This works well and doesn’t throw any errors, but no matter where I test the callback, I get the following warning:

3553: Function value used where type Boolean was expected. 
Possibly the parentheses () are missing after this function reference.

This annoys me, so I tried to get rid of the warning by testing for null and undefined. Those are causing errors I can't instantiate Function to null either.

I know, I know that real programmers only care about errors, not warnings. If this situation is not resolved, I will survive. But it bothers me! 🙂 I'm just neurotic, or is there actually some way to test if a real function is created without IDE bitch?

Similar to using typeof:

< pre>if(callback is Function){

}

I believe that if a function exists and is a function, it should evaluate to true, and if it is null or not a function, it should be false. (Although if this doesn’t work, please try if(callback&&&callback is function)()

So I have a class and I instantiate a variable callback as shown below Show:

public var callback:Function;

So far so good. Now, I want to add an event listener to this class And test whether there is a callback. I do this:

this.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent): void {
if (callback) {
// do some things
}
});

This works well and does not throw any errors, but no matter where I test the callback, I Will get the following warning:

3553: Function value used where type Boolean was expected. 
Possibly the parentheses () are missing after this function reference.

This annoys me, so I tried to get rid of the warnings by testing for null and undefined. Those caused errors. I also couldn’t instantiate Function to null.

I know, I know, the real The programmer only cares about errors, not warnings. If this situation is not resolved, I will survive. But it bothers me! 🙂 I am just neurotic, or is there actually some way to test if there is no IDE bitch The real function is created in the case of the child?

Similar to using typeof:

if(callback is Function){

}

I believe if the function exists and is a function it should evaluate to true, if it is null or not a function it should be false. (Although if this doesn’t work, try if(callback&&&callback is function){}

Leave a Comment

Your email address will not be published.