0

我试图揭示这个最初是位图但需要用作位图的影片剪辑图像。由于某种原因它不起作用......它没有抛出任何错误......我需要在用户按下它时屏蔽这个图像......然后与另一个位图进行比较以执行功能。但由于某种原因,正如我之前提到的,它没有成功。有人能帮帮我吗??这是它的代码...

import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.BitmapData;

var mouseclick:Number=0;
var maskedbg_mc:maskedbg = new maskedbg ();
var masking:Sprite = new Sprite()               

addChild (maskedbg_mc);
maskedbg_mc.x = 18;
maskedbg_mc.y = 343;
var bitmapDataCopy:BitmapData = new BitmapData(742,165,true,0x00FFFFFF);
var b:Bitmap = new Bitmap(bitmapDataCopy);

bitmapDataCopy.draw(maskedbg_mc);

b.mask = masking;
var Testing:BitmapData = new BitmapData(maskedbg_mc.width, maskedbg_mc.height, true, 0x00000000);


addChild(masking);


stage.addEventListener(MouseEvent.MOUSE_DOWN, Pressing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, Moving);
stage.addEventListener(MouseEvent.MOUSE_UP, Lifting);


function Pressing(event:MouseEvent):void {
mouseclick = 1;
}


function Moving(event:MouseEvent):void {
if (mouseclick == 1) {
masking.graphics.beginFill(0x000000);
masking.graphics.drawEllipse(mouseX, mouseY, 70, 60);
masking.graphics.endFill();
}
}


function Lifting(event:MouseEvent):void {
mouseclick = 0;
}

if ( bitmapDataCopy.compare(Testing) ==0 )
{
    trace ("Awesomness")
}
4

1 回答 1

1

俯瞰您的代码,我注意到您没有将“b”(被屏蔽的 DisplayObject)添加到显示列表中,而您正在添加实际上并未在代码中被屏蔽的“maskedbg​​_mc”。你有这两个显示对象的理由吗?

我建议您遵循动作脚本编码约定:

http://sourceforge.net/adobe/flexsdk/wiki/Coding%20Conventions/

当变量和函数的首字母大写时,您的代码看起来很混乱,它们看起来像类。

于 2013-02-17T05:23:26.687 回答