Skip to main content
Inspiring
May 9, 2009
Answered

Problem to draw a clip with a clip a cliparea

  • May 9, 2009
  • 1 reply
  • 745 views

Hello,

I have a clip, and I want to redraw only an area of that clip.

Therefore I use the following code where I use a simple rectangle with "hello" written inside it, its dimension are 200*100

I want to redraw only a part of 50*20 of that rectangle. Here is the code I used :

var clip:MovieClip=new MovieClip();

clip.graphics.beginFill(0x990000,1);

clip.graphics.drawRect(0,0,200,100);

clip.graphics.endFill();

var texte:TextField=new TextField();

texte.text="hello";

texte.x=50;

texte.y=50;

clip.addChild(texte);

this.addChild(clip);

var bmpData:BitmapData=new BitmapData(50,20);

var rect:Rectangle=new Rectangle(60,50,50,20);

bmpData.draw(clip,null,null,null,rect,false);

var bmp:Bitmap=new Bitmap(bmpData);

this.addChild(bmp);

bmp.y=150;

clip.visible=false;

Nothing shows up when I run the application, I expected to see to see a red rectangle 50*20 showing a portion of "hello" , but I didn't get it.

Can anybody tell me why?

Thanks in advance,

Pascal

This topic has been closed for replies.
Correct answer kglad

try:

var bmpData:BitmapData=new BitmapData(50,20);
var rect:Rectangle=new Rectangle(0,0,50,20);
var mat:Matrix = new Matrix();
mat.tx=-50;
mat.ty=-50;
bmpData.draw(clip,mat,null,null,rect,false);
var bmp:Bitmap=new Bitmap(bmpData);
this.addChild(bmp);
bmp.y=150;
clip.visible=false;

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 9, 2009

try:

var bmpData:BitmapData=new BitmapData(50,20);
var rect:Rectangle=new Rectangle(0,0,50,20);
var mat:Matrix = new Matrix();
mat.tx=-50;
mat.ty=-50;
bmpData.draw(clip,mat,null,null,rect,false);
var bmp:Bitmap=new Bitmap(bmpData);
this.addChild(bmp);
bmp.y=150;
clip.visible=false;
ritpasAuthor
Inspiring
May 9, 2009

Thanks kglad!

It works, could you just tell me why you used tx and ty properties of the matrix object? because I don't know why a transition was necessary to get it

kglad
Community Expert
Community Expert
May 9, 2009

because your text was at 50,50.

so, you need move your clip to -50,-50 so its upper left corner will be at 0,0 - the upper left corner of your bitmapdata instance.