# Cropping with actionscript clips

**URL:** <https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495>\
**Category:** flash\
**Created:** [January 17, 2003, 10:14pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495 "2003-01-17T22:14:52Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalvi](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@dalvi](https://forum.kirupa.com/u/dalvi)\
**Post date:** [January 17, 2003, 10:14pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/1 "2003-01-17T22:14:52Z")

</div>

There seems to be difficulties cropping clips with clips created in ActionScript.

like createEmptyMovieClip, duplicateMovieClip, setMask()

Can you find a solution for this ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 17, 2003, 10:37pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/2 "2003-01-17T22:37:24Z")

</div>

What difficulty are you having?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 17, 2003, 11:32pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/3 "2003-01-17T23:32:02Z")

</div>

Well, I can’t find a way to mask a movieclip with another created with pure ActionScript.  
The only way is to use mc created in Flash design which is not a solution.

Do you think I can crop a clip in other way using only ActionScript ?

Tnx.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 17, 2003, 11:41pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/4 "2003-01-17T23:41:05Z")

</div>

Well you can only use 1 mask per movie clip, maybe that is the problem?

Also, if you are just using createEmptyMovieClip, what are you masking? Are you duplicated a clip from the library? Or a clip on the stage? Or are you using the Drawing API?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 9:07am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/5 "2003-01-18T09:07:06Z")

</div>

All I do is ActionScript, not Flash Design  
So

1. \_root.createEmptyMovieClip
2. Various children clips within the 1st mc
3. duplicate the 1st mc for using as a mask for the children

Normally, the 1st movieclip should crop all children to it’s original dimensions. This is not the case in MX, at least text box doens’t conform to this.

So what I have to do is to crop this notty children and I’m thinking to duplicate the 1st mc and use it as a mask for the children.

If I use a Flash Design mc, it works, but I have to use an ActionScript mc, since I don’t know what the original mc will be like (box, filled circle, star, etc.)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 9:10am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/6 "2003-01-18T09:10:18Z")

</div>

Well yeah, but I don’t understand how you can mask an empty movie clip.

It is empty. There is nothing to mask, or to have mask it.

Can you show me the script you are using?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 9:16am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/7 "2003-01-18T09:16:54Z")

</div>

It is not empty. I populate it with ActionScript figures. Why do ya think I need to crop an empty clip ?

Source code

MaskedClip = function (name, x, y) {  
\_root.createEmptyMovieClip(name, 2);  
obj = eval("\_root."+name);  
mainclip.duplicateMovieClip(“clipper”, 5);  
// clipper.\_x=mainclip.\_x+50;  
mainclip.setMask(box);  
trace(clipper.\_alpha);  
setProperty(box, \_x, 100);  
setProperty(clipper, \_height, 500);  
// clipper.\_width=500;  
// trace(clipper.\_width);  
setProperty(name, \_x, x);  
setProperty(name, \_y, y);  
// setProperty(mainclip, \_width, 300); // strange behavior  
with (obj) {  
beginFill(0xAAAAAA, 50);  
lineStyle(1, 0xFFFFFF, 100);  
lineTo(300, 0);  
lineTo(300, 100);  
lineTo(0, 100);  
lineTo(0, 0);  
endFill();  
}  
obj.createEmptyMovieClip(“childbox”, 1);  
with (eval(obj.childbox)) {  
beginFill(0xFFAA00, 50);  
lineStyle(1, 0xFFFFFF, 100);  
moveTo(200, 50);  
lineTo(400, 50);  
lineTo(400, 150);  
lineTo(200, 150);  
lineTo(200, 50);  
endFill();  
}  
};  
box1 = new MaskedClip(“mainclip”, 100, 200);

* * *

I don’t think this is a workable script anymore but it’s enough to get an idea.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 9:27am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/8 "2003-01-18T09:27:21Z")

</div>

Did you write this code yourself?

This looks like you were attempting Object Oriented Programming, but at the same time, it doesn’t. Like you use obj and new Object, but I don’t see any constructor prototypes.

I don’t know much OOP though, I am extremely novice in it.

One thing I noticed in your script though is that you use the setMask to mask an object called “box” (no quotes), but throughout the script, you create no object called “box”.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 9:35am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/9 "2003-01-18T09:35:16Z")

</div>

Alright, well it is 4:30am here. I have to get to bed now.

I will work more on this tomorrow if I can.

But so far to me… it looks like your code is all sorts of screwey, but what do I know :q: 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 8:10pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/10 "2003-01-18T20:10:54Z")

</div>

OOP in ActionScript is a little bit differend than in C++ or st. like that.

box is an Flash Design mc 🙂 This one works as a mask, but the clipper won’t

Quotes or no quotes, there’s no problem with my code I assure you. It should work.

The code is messy after many attempts to debug and test some theories.

Just try to mask an AS mc with another AS mc (no Flash Design in it).

Tnx 4 trying.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 8:15pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/11 "2003-01-18T20:15:37Z")

</div>

Yeah, OOP is probably a tad bit different in AS. I tried studying OOP, but it gave me a headache, so I considered myself unprepared for it at the moment. I know the basics of it though.

Also, on another note, some of the code in your file is… outdated.

setProperty is way old. Lines like setProperty(box, \_x, 100) and setProperty(clipper, \_height, 500) can be changed into box.\_x = 100 and clipper.\_height = 500.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 8:32pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/12 "2003-01-18T20:32:12Z")

</div>

Well, the reason I used setProperty is cuz you can’t just use

a= function(name) {  
createEmptyMovieClip(name, 15);  
name.\_x=10 // this won’t work  
}

name being a string like a(“my\_mc”);

You have to either use

obj=eval(name);  
obj.\_x=10;

or simply

setProperty(name, \_x);

I assure you setProperty is not at all obsolete, it is used in Flash ActionScript Help (ActionScript Dictionary…)

But pls, just help me if u can with that masking

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 10:00pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/13 "2003-01-18T22:00:04Z")

</div>

Well you could use something like \_root[name] I believe.

And I will see what I can do about that masking.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 18, 2003, 10:10pm UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/14 "2003-01-18T22:10:06Z")

</div>

How about something like this?

```auto
MovieClip.prototype.buildSquare = function(fillColor, fillAlpha, lineThickness, lineColor, lineAlpha, x, y, xscale, yscale) {
	this.beginFill(fillColor, fillAlpha);
	this.moveTo(-50, -50);
	this.lineStyle(lineThickness, lineColor, lineAlpha);
	this.lineTo(-50, 50);
	this.lineTo(50, 50);
	this.lineTo(50, -50);
	this.lineTo(-50, -50);
	this.endFill();
	this._x = x;
	this._y = y;
	this._xscale = xscale;
	this._yscale = yscale;
};
_root.createEmptyMovieClip("box1", 1);
_root.box1.buildSquare(0xE6E6E6, 100, 1, 0x000000, 100, 100, 200, null, null);
_root.createEmptyMovieClip("box2", 2);
_root.box2.buildSquare(0xFF9900, 100, 1, 0x000000, 100, 150, 250, null, null);
//_root.box1.setMask(_root.box2);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 1:50am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/15 "2003-01-19T01:50:05Z")

</div>

Great!

The key was using “this”. And I solved my problems with the children including textfields.

Thank you very much! :hat:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 4:51am UTC](https://forum.kirupa.com/t/cropping-with-actionscript-clips/11495/16 "2003-01-19T04:51:06Z")

</div>

No problem man. I am glad you got everything working 🙂
