MOUSE_OVER/MOUSE_OUT与ROLL_OVER/ROLL_OUT的区别
MOUSE_OVER和MOUSE_OUT除了对监听该事件的控件作出响应,同时也对该控件的所有子控件(拥有该事件)进行响应
ROLL_OVER和ROLL_OUT则相反,只响应监听该事件的控件
Code
package
{
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
public class Sample0814 extends Sprite
{
public function Sample0814()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
var box:Sprite = new Sprite();
box.graphics.beginFill(0xCCCCCC);
box.graphics.drawRect(0,0,200,200);
box.graphics.endFill();
box.x = box.y = 50;
// box.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
// box.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
box.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
box.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
this.addChild(box);
var item:Sprite = new Sprite();
item.graphics.beginFill(0xFF0000);
item.graphics.drawRect(0,0,80,80);
item.graphics.endFill();
item.x = item.y = 60;
box.addChild(item);
}
private function mouseOverHandler(event:MouseEvent):void
{
trace("mouse over");
}
private function mouseOutHandler(event:MouseEvent):void
{
trace("mouse out");
}
private function rollOverHandler(event:MouseEvent):void
{
trace("roll over");
}
private function rollOutHandler(event:MouseEvent):void
{
trace("roll out");
}
}
}
{
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
public class Sample0814 extends Sprite
{
public function Sample0814()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
var box:Sprite = new Sprite();
box.graphics.beginFill(0xCCCCCC);
box.graphics.drawRect(0,0,200,200);
box.graphics.endFill();
box.x = box.y = 50;
// box.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
// box.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
box.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
box.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
this.addChild(box);
var item:Sprite = new Sprite();
item.graphics.beginFill(0xFF0000);
item.graphics.drawRect(0,0,80,80);
item.graphics.endFill();
item.x = item.y = 60;
box.addChild(item);
}
private function mouseOverHandler(event:MouseEvent):void
{
trace("mouse over");
}
private function mouseOutHandler(event:MouseEvent):void
{
trace("mouse out");
}
private function rollOverHandler(event:MouseEvent):void
{
trace("roll over");
}
private function rollOutHandler(event:MouseEvent):void
{
trace("roll out");
}
}
}