开发者

Actionscript / Flex: a question about handleAllEvents() method

in Adobe tutorials, they suggest to create a class to handle the events (see below the copy/pasted code, and link to page).

I was wondering if I have to handle all events with the function handleAllEvents, using if statements to check if the target is the one I want, and the event is the one I want.

i.e. if (event.type=="click") && (event.currentTarget == "myId")

Should I have a list of ifs (for each target and each event typ开发者_开发知识库e ?)

thanks

// events/MyStaticEventHandler.as

package { // Empty package.

    import flash.events.Event;
    import mx.controls.Alert;

    public class MyStaticEventHandler {
        public function MyStaticEventHandler() {
            // Empty constructor.
        }

        public static function handleAllEvents(event:Event):void {
            Alert.show("Some event happened.");
        }
    }
}

Link (at the bottom): http://livedocs.adobe.com/flex/3/html/help.html?content=events_05.html


If you use one handler for all events, you'll likely end up casting the generic incoming event to the more specific event inside each of the different if statements.

I would at the least have different handlers for different event types.

Ultimately it depends on what you need the event handler(s) to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜