我正在学习 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 .. ;
}
}
有没有办法做到这一点,或者也许是更好的思考方式?