views:

418

answers:

4

In Flash Professional CS4, I get "migration issue" warnings when I use mouse/keyboard input handler names such as onMouseDown, onKeyUp, etc., even though I have added event listeners for them. These names are perfectly legal for functions, but since these were automatically fired in ActionScript 2.0, we are now (albeit sensibly) warned that their use is no longer automatic in AS3.

I understand the purpose of the warnings, but they aren't useful for me. I want to suppress these warnings, but without suppressing any other warnings, which I generally do find useful.

E.g., when I use code like this:

/** @constructor */
public function MyClass() {
  addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}

protected function onMouseDown(e:MouseEvent):void {

I get an annoying warning like this:

Warning: 1090: Migration issue: The onMouseDown event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'mouseDown', callback_handler).

There are flex compiler (mxmlc) flags (and a Flash Pro setting) which can suppress actionscript warnings, or all warnings, but I don't want that. That's to general.

Ideally I could suppress a specific error/warning number (Warning #1090).

Edit: I've found more "advanced" compiler flags with mxmlc -help advanced, which look promising. Specifically, the following seem like likely candidates:
warn-deprecated-event-handler-error
warn-deprecated-function-error
warn-deprecated-property-error

How do I get Flash to use these?

Edit 2: I found a flex-info.xml style document in the Flash User Data dir.
[userdatafolder]/Adobe/Flash CS4/en/Configuration/ActionScript 3.0/FlexInfo.xml However, this file contains a disappointing comment: <!-- Flash does not support most flex-config options. -->, and doesn't seem to respond to my directives even after restarting flash.
This is getting sad.

Edit 3: Found an issue "Erroneous, annoying "Migration issue" warnings" on Adobe bug tracker. A fix is confirmed for the Flex SDK, but no mention of Flash...

+1  A: 

Why are you overriding that? It never existed in the first place. The error message is actually telling you something useful. Don't suppress it.

If you want to create an event handler called onMouseDown, try something like

private function onMouseDown(e:MouseEvent) : void {
  // statements
}
Robusto
Ah crap, thank you for pointing that out. The override keyword is a typo - I copied the line from a subclass. :/
aaaidan
A: 

I agree with the previous post; the message is trying to tell you that you need to register that event handler. Just adding a method called onMouseDown() won't do it. What you need to do is to add something like

addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);

in either your constructor or maybe in the parent component.

ilikeorangutans
Hmm, perhaps I need to make it clear that I have added the event listener, and I still get the warning... thanks for comment.
aaaidan
+1  A: 

What about changing the name of the function being called from onMouseDown to handlerOnMouseDown. Would it solve the issue?

Are you using Flex Builder?
If so, go to Project -> Properties -> Flex Compiler. There you can add arguments to the compiler.

Frank
Yes, that would stop the warnings. But it wouldn't soothe my aching heart. I like "onMouseDown" more than "onMouseDownHandler" or "onMouseDown2", etc...
aaaidan
And no, using Flash Builder (CS4).
aaaidan
+4  A: 

Hello Aaaidan,

You can if you edit EnabledWarnings.xml in $Flash/$LOCALE/Configuration/Actionscript 3.0/EnabledWarnings.xml, where $Flash is the path to Flash inside your Applications/Program Files folder and $LOCALE is your language.

e.g.

/Applications/Adobe Flash CS4/en/Configuration/ActionScript 3.0/EnabledWarnings.xml

You will need to edit line 29, setting the enabled attribute to false for warning with id 1090:

<warning id="1090" enabled="false"  label="kWarning_DepricatedEventHandlerError">EventHandler was not added as a listener.</warning>

quick sidenote:

Flash Builder (CS4)

is a confusing term. After Flex Builder 3, Flex Builder got renamed to Flash Builder, there is no Flash Builder CS4. The regular Flash IDE is known as Flash Professional/Flash Professional CS4, this was to avoid confusion between products with similar names: Flash Catalyst, Flash Builder(was Flex Builder), Flash Professional. Obviously it doesn't always work that great :)

George Profenza
Man. First accurate answer so far, will check it out.
aaaidan
Excellent. This is exactly the answer I was looking for. Thank you so much, George, you're a saint. No pun intented.
aaaidan
Oh, and thanks for clearing up that stuff about Flash Builder/Flash Professional.
aaaidan
No worries, glad that helps. There only a few warnings that are important, most of them are related to migration issues.
George Profenza