0

What is easiest way to do this:

on stage 400x400 I have rect 200x200, inside rect are few mc objects. I can drag & drop StartDrag and add 200x200 as limits for this movement, but how I can do that when drag obejct they can be "visible" just near the border of rect, in other words if I drag circle into 200x200 rectangle how to make "disappear" part of that circle when it touch the border of 200x200 rect?

hmmftg
  • 1,274
  • 1
  • 18
  • 31
Simon
  • 121
  • 7
  • 19

1 Answers1

4

You need to add a mask to the circle. Here would be an example for the above scenario:

var squareBG:Shape = new Shape();
squareBG.graphics.beginFill(0);
squareBG.graphics.drawRect(0,0,200,200);
squareBG.graphics.endFill();
addChild(squareBG);

var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xFF0000);
circle.graphics.drawCircle(0,0,100);
circle.graphics.endFill();
circle.y = 125;
addChild(circle);

var circle2:Sprite = new Sprite();
circle2.graphics.beginFill(0xFFFF00);
circle2.graphics.drawCircle(0,0,100);
circle2.graphics.endFill();
addChild(circle2);
circle2.x = 150;

var myMask:Shape = new Shape();
myMask.graphics.copyFrom(squareBG.graphics);    
addChild(myMask);

var myMask2:Shape = new Shape();
myMask2.graphics.copyFrom(squareBG.graphics);    
addChild(myMask2);

circle.mask = myMask;
circle2.mask = myMask2;
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • LondonDrugs_MediaServices thanks for fast answer, and your solution works great, but there is 1 problem: When I add more objects (let say circles and squares) only LAST one is "inside". I define 1 mask, and then ad 1 by 1 new circles but only last one stay inside when drag, other I can pull out of mask, suggestions? – Simon Aug 03 '12 at 17:41
  • Though I've never had need to try it, I think AS3 masks can only be attached to one object. You'll likely need to create a new mask for each circle. If your mask is a Shape, the graphics.copyFrom() function makes it pretty quick to duplicate your mask. – BadFeelingAboutThis Aug 03 '12 at 17:48
  • Tried, and now just LAST object is VISIBLE (it looks that mask from newly added covers previous object) any ideas? – Simon Aug 03 '12 at 17:54
  • If the updated code doesn't help, post your ACTUAL code for further help. – BadFeelingAboutThis Aug 03 '12 at 18:32
  • Thanks LondonDrugs_MediaServices, this works, you helped a lot! – Simon Aug 04 '12 at 10:02