マウスイベントのフローで混乱するのでおさらい
いまだにマウスイベントのフローで混乱するのでおさらい
とりあえずMouseEvent.stopPropagation()するかしないかで工夫すればよい?
それじゃあカバーできないケースもありそう。。。
//参考: ActionScript 3.0 のプログラミング > イベントの処理 > イベントフロー
http://livedocs.adobe.com/flash/9.0_jp/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000137.html#wp777600
//参考: stopPropagation()とstopImmediatePropagation()
http://www.nankaifactory.com/blog/2008/06/stoppropagationstopimmediatepr.html
♥0 |
Line 70 |
Modified 2010-01-27 22:03:01 |
MIT License
archived:2017-03-10 00:46:02
ActionScript3 source code
/**
* Copyright mi77 ( http://wonderfl.net/user/mi77 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/n2P0
*/
/*
いまだにマウスイベントのフローで混乱するのでおさらい
とりあえずMouseEvent.stopPropagation()するかしないかで工夫すればよい?
それじゃあカバーできないケースもありそう。。。
//参考: ActionScript 3.0 のプログラミング > イベントの処理 > イベントフロー
http://livedocs.adobe.com/flash/9.0_jp/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000137.html#wp777600
//参考: stopPropagation()とstopImmediatePropagation()
http://www.nankaifactory.com/blog/2008/06/stoppropagationstopimmediatepr.html
*/
package {
////////////////////////////////////////////////////
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class FlashTest extends Sprite
{
private var _txt:TextField;
private var _txt2:TextField;
public function FlashTest()
{
var sq0:Square = new Square(0x666666, 150);
addChild(sq0);
sq0.x=sq0.y=150;
sq0.name = "親";
//
var sq1:Square = new Square(0x000000, 50);
sq0.addChild(sq1);
sq1.x=sq1.y=50;
sq1.buttonMode=true;
sq1.name = "子";
//
_txt = new TextField();
addChild(_txt);
_txt.height = 20;
_txt.width = 500;;
_txt.x = 10;
_txt.y = 10;
//
_txt2 = new TextField();
addChild(_txt2);
_txt2.height = 20;
_txt2.width = 500;
_txt2.x = 10;
_txt2.y = 30
//
sq0.addEventListener(MouseEvent.MOUSE_OUT, mouseOutH);
sq0.addEventListener(MouseEvent.MOUSE_OVER, mouseOverH);
//
sq1.addEventListener(MouseEvent.MOUSE_OUT, mouseOutChildH);
sq1.addEventListener(MouseEvent.MOUSE_OVER, mouseOverChildH);
sq1.addEventListener(MouseEvent.CLICK, mouseClickChildH);
}
private function mouseOutH(e:MouseEvent):void
{
e.stopPropagation();
_txt.text = e.currentTarget.name + " OUT ";
}
private function mouseOverH(e:MouseEvent):void
{
e.stopPropagation();
_txt.text = e.currentTarget.name + " OVER ";
}
private function mouseOutChildH(e:MouseEvent):void
{
_txt2.text = e.currentTarget.name + " OUT ";
}
private function mouseOverChildH(e:MouseEvent):void
{
_txt2.text = e.currentTarget.name + " OVER ";
}
private function mouseClickChildH(e:MouseEvent):void
{
_txt2.text = e.currentTarget.name + " CLICK";
}
}
////////////////////////////////////////////////////
}
import flash.display.*;
internal class Square extends Sprite
{
public function Square(color:int, size:int)
{
graphics.beginFill(color);
graphics.drawRect(0, 0, size, size);
}
}