こんにちは、ビデオを表示する単純なアプリケーションがあり、ユーザーがマウスでそれを消去すると、次のメッセージが表示されます。通常モードでは正常に動作しますが、全画面モードではすべて正常に動作します。これが私のコードです。
package {
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.events.FullScreenEvent;
public class MaskTestMain extends MovieClip {
private var enableMasking:Boolean = true; //set this to false to turn off masking and just draw lines
private var tempGraphics:Graphics;
public function MaskTestMain() {
if(stage) init(null);
else this.addEventListener(Event.ADDED_TO_STAGE, init);
video.visible = false;
objectToMask_mc.visible = false;
}
private function init(event:Event)
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, onResizeHandler);
onResizeHandler(null);
startButton.addEventListener(MouseEvent.CLICK, goFullScreenAndStartDraw)
}
private function goFullScreenAndStartDraw(event:MouseEvent):void
{
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
startButton.visible = false;
video.visible = true;
objectToMask_mc.visible = true;
video.v.play();
updateMask();
tempGraphics = drawingBoard_mc.graphics;
tempGraphics.clear();
tempGraphics.lineStyle(200, 0xff0000, 1);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onStartDrawing);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreenChange);
stage.addEventListener(MouseEvent.MOUSE_UP, onStopDrawing);
}
private function onFullScreenChange(event:FullScreenEvent):void
{
onResizeHandler(null);
}
private function onResizeHandler(event:Event):void
{
drawingBoard_mc.x = 0;
maskHolder_mc.y = 0;
trace("onResizeHandler");
drawingBoard_mc.x = drawingBoard_mc.y = 0;
startButton.x = stage.stageWidth/2;
startButton.y = stage.stageHeight/2;
maskHolder_mc.x = maskHolder_mc.y = 0;
video.height = stage.stageHeight;
video.scaleX = video.scaleY;
video.x = stage.stageWidth/2 - video.width/2;
video.y = 0;
objectToMask_mc.x = video.x;
objectToMask_mc.y = video.y;
objectToMask_mc.width = video.width + 150;
objectToMask_mc.height = video.height +180;
}
//- start drawing lines:
function onStartDrawing(e:MouseEvent):void {
tempGraphics.moveTo(mouseX, mouseY);
addEventListener(Event.ENTER_FRAME, onDrawFrame);
}
//- stop drawing lines:
private function onStopDrawing(e:MouseEvent):void {
removeEventListener(Event.ENTER_FRAME, onDrawFrame);
}
//- called on every frame while drawing - draws the next line and calls masking function:
private function onDrawFrame(e:Event):void {
tempGraphics.lineTo(mouseX, mouseY);
updateMask();
}
//- when masking is enabled, this uses the dynamic lines to create a mask:
private function updateMask():void {
if (enableMasking) {
//remove all old masks from the maskHolder:
while (maskHolder_mc.numChildren > 0) {
maskHolder_mc.removeChildAt(0);
}
objectToMask_mc.mask = null; //clear the previous mask form the object
//parameters of bitmapData MUST be set to: ([width], [height], true, 0) to get the transparency correct:
var myBitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0);
drawingBoard_mc.visible = true; //make this visible for creating the bitmap
myBitmapData.draw(drawingBoard_mc); //create a bitmap copy of the drawing board
drawingBoard_mc.visible = false; //hide the drawing board again
var printBitmap:Bitmap = new Bitmap(myBitmapData); //create a bitmap from the bitmap data
printBitmap.smoothing = true; //optional
var maskClip:MovieClip = new MovieClip; //create a movieclip to act as the new mask
maskClip.addChild(printBitmap); //add the bitmap copy of the drawing board to the new mask movieclip
maskClip.cacheAsBitmap = true; //IMPORTANT: mask movieclip cacheAsBitmap = true or this doesn't work
maskHolder_mc.addChild(maskClip); //add the new mask to the maskHolder
objectToMask_mc.cacheAsBitmap = true; //IMPORTANT: masked movieclip cacheAsBitmap = true or this doesn't work
objectToMask_mc.mask = maskClip; //set our new mask on the object
}
}
}
}