マウスオーバーを処理するサンプル
MouseEvent.MOUSE_OVERのイベントハンドラを設定するだけ。
- Graphicsを使って書いた円や線もうまいこと当たり判定してくれます。
- Filterを利用して作成した影には反応しないようだ。
package { import flash.display.*; import flash.filters.*; import flash.events.MouseEvent; import flash.text.*; // マウスオーバーイベントを処理するサンプル public class Sample extends Sprite { public function Sample(){ // 円 var circle:Sprite = new Sprite(); addChild(circle); var g:Graphics = circle.graphics; g.beginFill( 0xFF4444 ); g.drawCircle( 60, 60, 50 ); g.endFill(); // 線 g.lineStyle( 1, 0xFF4444 ); g.moveTo( 0, 100 ) g.lineTo( 200, 10 ) // 影を落とすフィルタを適用 circle.filters = [new DropShadowFilter( 3.0, 45, 0x000000 )]; var text:TextField = new TextField(); text.x = 10; text.y = 10; text.width = 200; text.height = 20; text.text = "mouse over!!"; text.visible = false; this.addChild(text); // イベントハンドラを設定 circle.addEventListener(MouseEvent.MOUSE_OVER, function(ev:flash.events.MouseEvent):void { text.visible = true; }); circle.addEventListener(MouseEvent.MOUSE_OUT, function(ev:flash.events.MouseEvent):void { text.visible = false; }); } } }