1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

イベントリスナーで引数を渡す

Posted at

FlashでaddEventListenerする時、関数に引数を渡したくなりませんか?私はなります。のでメモ。

ActionScript3.0
stage.addEventListener(MouseEvent.CLICK, hoge("ほげほげ"));

function hoge(hogehoge:String):Function {
  return function(e:MouseEvent):void {
    trace(hogehoge);
    // ステージをマウスクリックで hogehoge(ほげほげ)を出力
  }
}

何かこう、めんどいな…

なお、ここで追加した無名関数を削除するには、arguments.calleeを使います。

ActionScript3.0
stage.removeEventListener(MouseEvent.CLICK, arguments.callee);

うっかり消し忘れにご注意。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?