实现鼠标点击被遮挡的MC的功能
假如有两个MC,一个叫A,一个叫B
A放在B的上面,也就是说A可以遮住B,而且现在A把B完全遮挡了
B上有MouseEvent.CLICK事件的监听
代码如下:
this.addChild(createRectMovieClip(50, 50, 0x112233, {x:50, y:50, name:'HandsomeMonkeyKing'}, 1.0)).addEventListener(MouseEvent.CLICK, mouseEvent);
this.addChild(createRectMovieClip(90, 90, 0x778899, {x:30, y:30, name:'FiveFingerMountain'}, 0.9)).addEventListener(MouseEvent.CLICK, mouseEvent);
function mouseEvent (event:MouseEvent):void
{
trace(event.target.name); // return FiveFingerMountain
}
function createRectMovieClip ($width:Number = 0, $height:Number = 0, $color:uint = 0xFFFFFF, $init:Object = null, $alpha:Number = 1, $lineAlpha:Number = 0, $thickness:Number = 0, $lineColor:Number = 0):MovieClip
{
var MC:MovieClip = new MovieClip();
MC.graphics.lineStyle($thickness, $lineColor, $lineAlpha);
MC.graphics.beginFill($color, $alpha);
MC.graphics.drawRect(0, 0, $width, $height);
for (var i:String in $init) MC[i] = $init[i];
return MC;
}
结论是上面的MC可以遮挡住下方MC的点击,无论上层的MC是否有listener
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |