Reputation: 13109
I have run into strange behavior drawing a sprite into a BitmapData. This sprite looks fine when drawn directly to the screen. But when this sprite is drawn into a BitmapData, the sprite is being masked... but there is no such mask applied to that sprite!
This "bad mask" can be toggled off and on... by applying / not-applying a different mask to the sprite I am drawing. This mask is not the same shape or location as the "bad mask".
alt text http://img5.imageshack.us/img5/8310/masked.png
I am wondering if I I am doing something wrong or if this is a bug? I am adding masks in the manner described in the documentation. The "bad mask" appears to get its coordinates from the position of the sprite I am drawing (drawingSprite) relative to its parents.
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import mx.core.UIComponent;
public class tmpa extends UIComponent
{
public function tmpa( ):void
{ var topSprite:Sprite = new Sprite();
topSprite.x = 0;
topSprite.y = 0;
addChild( topSprite );
var canvasSprite:Sprite = new Sprite();
canvasSprite.x = 5;
canvasSprite.y = 35;
topSprite.addChild( canvasSprite );
var drawingSprite:Sprite = new Sprite();
canvasSprite.addChild( drawingSprite );
var maskSp:Sprite = new Sprite();
maskSp.graphics.beginFill( 0xFFFFFF, 1 );
maskSp.graphics.drawRect( 0, 0, 200, 200 );
maskSp.graphics.endFill();
//toggle these two lines of code
canvasSprite.addChild( maskSp );
drawingSprite.mask = maskSp;
drawingSprite.graphics.beginFill( 0xFF0000, 1 );
drawingSprite.graphics.drawRect( 0, 0, 200, 200 );
drawingSprite.graphics.endFill();
drawingSprite.graphics.beginFill( 0x00FF00, 1 );
drawingSprite.graphics.drawCircle( 0, 0, 100 );
drawingSprite.graphics.endFill();
//a snapshot with default blue background
var bmd:BitmapData = new BitmapData( 100, 100, false, 0x0000FF );
bmd.draw( drawingSprite );
var bm:Bitmap = new Bitmap( bmd );
bm.x = 300;
bm.y = 35;
addChild( bm );
}
}
}
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:a="*" width="100%" height="100%">
<a:tmpa id="t" width="100%" height="100%" x="0" y="0" left="0" top="0"/>
</mx:Application>
Upvotes: 1
Views: 5611
Reputation: 27045
Changing the mask adding lines to:
canvasSprite.addChild( maskSp );
canvasSprite.mask = maskSp;
Solves the problem, so there is likely some confusion with the relative coordinate spaces of the clips. I think you should keep your mask on the same level as your masked DisplayObject in your displaylist to avoid confusion.
Upvotes: 1