私は ActionScript 3 を学んでおり、現時点ではhttp://www.senocular.com/flash/tutorials/as3withmxmlc/のチュートリアルに従っています。ステージ上にボールを置き、ユーザーがそれをドラッグできるようにする簡単なアプリケーションについて説明します。ただし、特にユーザーがポインターをステージからドラッグした場合を処理しないため、バグがあります。これにより、ケースを処理するためのより良い方法について考えるようになりました。手始めに、MOUSE_UP イベントの処理方法を検討しています。次のように書きたいと思います。
public class Test extends Sprite
{
public function Test(stage:Stage)
{
mySprite = SomeSpriteClass()
stage.addEventListener(MouseEvent.MOUSE_UP, handleStageMouseUp);
mySprite.addEventListener(MouseEvent.MOUSE_UP, handleSpriteMouseUp);
}
private function handleStageMouseUp(event:MouseEvent):void {
// how do I determine here if there was also a MOUSE_UP on the Sprite?
// Perhaps I could check the click coordinates of 'event' to see if
// they are superimposed on the Sprite.
}
private function handleSpriteMouseUp(event:MouseEvent):void {
// I don't need this method if I can handle all cases in the
// method above.
}
}
発生するこの問題は、ActionScript3 が使用するイベント モデルでは、イベントの組み合わせを含むケースを探す方法がわからないということです。または、上記の handleStageMouseUp() のコメントに書いたように、「mySprite」でマウス イベントが発生するかどうかを確認できます (どうすればよいでしょうか?)
私が本当にやりたいことは、すべてのケース ロジックを次のように結合できるようにすることです。
private function handleAllCases(...):void {
if (..mouse up on stage but not sprite..) {
.. handle case ..;
} else if ( .. mouse up on both stage and sprite .. ) {
.. handle case .. ;
}
}
これを行う方法、またはそれについて考えるより良い方法はありますか?