Actionscripting masks

Just completed the Inigo Montoya’s tutorial on scripting mask. (Very nice). However, I noticed two things I wanted to improve on.

First:

The camera gadget movie clip slides beyond the bounds of the the pictures. I modified the script in the following way:
//------------------------------------------------------
onClipEvent(enterFrame){
getlimits=_root.normalpic.getBounds(_root);
if(_root._xmouse>=getlimits.xMin + 60 &&
_root._xmouse<=getlimits.xMax - 60 &&
_root._ymouse>=getlimits.yMin &&
_root._ymouse<=getlimits.yMax){
this._x=_root._xmouse;

}

}

I added (and subtracted) 60 pixels from the x coordinates and it works. But is this is good scripting technique or not?

Second:

The slider always loads to the far left outside of the bounds of the picture until the pointer enters the movie. How would one correct this??

Thanks

Hi there,

As for your two questions, here’s my two cents.

  1. Adding and subtracting 60 pixels should be okay: if it works, it works! The only reason (that I can think of) one would want to avoid this is because you don’t know how big or small the clip being masked is. Suppose you used this script for another movie, one where that 60 pixel padding was needed. In that case you might find your mask too small to cover everything. That’s why using getBounds() will work for any clip, no matter how big or small it is (although, as you’ve probably noticed, getBounds() can tend to be slightly inaccurate). The idea is have your scripts be as portable as possible: if you can write scripts that you can use again and again without having to modify a single line of the code, then that’s excellent scripting.

  2. I glanced at the tutorial quickly, so I may be wrong on this, but it looks like you author the movie to have the square slider begin on the far left. So when the movie is published, that’s where it appears. You can have it move wherever you want it to in the authoring tool, and when the movie is published, that’s where the clip will be. Or you can add some actionscript at the beginning of the movie that will place the clip at the x, y coordinates you want it:


_root.theHoleInYourMaskMC._x = 100;
_root.theHoleInYourMaskMC._y = 200;

That should do the trick. Where exactly do you want to place the mask, if not the far left?

Good point.

Maybe you have some insight on this hurdle I just came across.

When using the setMask method, it doesnt work on duplicate MCs that are located on other levels. In other words if I try to mask something this…

for (i=0; i <10; i++) {
duplicateMovieClip(packet_mc, “packet”+i+"_mc", i);
_root[“packet”+i+"_mc"]._x = random(400);
_root[“packet”+i+"_mc"]._y = random(220);
_root[“packet”+i+"_mc"]._alpha = random(100);
_root[“packet”+i+"_mc"]._xscale = random(50);
_root[“packet”+i+"_mc"]._yscale = random(50);
};

…setMask won’t mask anything.

Are you aware of a way to to create a looping mask that would work on all the instances of this MC??

1 mask per clip. Since you can’t mask multiple clips, using setMask on multiple duplicate clips will not work.

Unless you duplicate them within 1 movie clip and mask that main movie clip.

Can you have a movieclip as a mask on the main stage?

Sure, and you can set the mask at authoring time or use actionscript to set that mask at run time.