Adding a mask using Actionscript?

Hi,

I have a flash movie, which intends to dynamically place and animate images over the top of one another... this is currently being done by loading the images in dynmaically into a MovieClip object, which is created on-the-fly. That bit works fine.

I also want these images (named "mc")  to be masked, so I attempt to set a mask on this MovieClip object using the following code:

mc.setMask(mask_mc);

I'm sure I've done something totally wrong, but I have no idea what.


Any ideas?

Thanks
//Import the classes
import mx.transitions.Tween;
import mx.transitions.easing.*;
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mcListener:Object = new Object();
var _interval:Number = 0;
 
// use the object to capture events from the MovieClipLoader class
mcLoader.addListener(mcListener);
 
// set this to null to begin with
mcListener.currentMC = null;
 
// event called when the image has completed loading
mcListener.onLoadInit = function(mc:MovieClip) {
 
		// move the image with easing over 3 seconds
		var tw1:Tween = new Tween(mc, "_y", Bounce.easeOut, -600, 0, 2, true);
		tw1.onMotionFinished = function() {
                // remove the old movieclip
                trace("deleting: " + _root[mcListener.currentMC]);
                removeMovieClip(_root[mcListener.currentMC]);
                trace("should be undefined: " + _root[mcListener.currentMC]);
                // set the current movie clip to the one just loaded
                mcListener.currentMC = mc._name;
                // stop for a period of time
                // load the next image after a period of time
                _root._interval = setInterval(_root, "LoadNextImage", 6000);
								
        };
};
 
 
// your generateRandom function here
function generateRandom(min, max) {
        var num = min + random(max - min);
        //trace("Last Num:" + lastNum);
        if (num == this.lastNum) {
                        return generateRandom(min, max);
                        //return;
        }
        this.lastNum = num;
       // trace("current num:" + num);
        return num;
}
function LoadNextImage() {
        // clear the interval if any
        clearInterval(_root._interval);
        //specify random conditions
        var imageNum:Number = generateRandom(1, 7);
        // get the first image
        var imageName:String = "http://mydomain.com.au/flash/images/" + "" + imageNum + ".jpg";
        trace("---------------");
        trace(imageName);
        // create an empty movie clip (will always be on top and starts at (0,0))
        var mc:MovieClip = _root.createEmptyMovieClip("img" + imageNum, getNextHighestDepth(), {_x:0, _y:0});
		mcLoader.loadClip(imageName, mc);
        trace("________");
        trace("mc: " + mc);
		
		
}
 
mc.setMask(mask_mc);
 
 
// Start everything
LoadNextImage();

Open in new window

mkofahlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

najhCommented:
at a glance, it looks like mc is first declared in that function , "LoadNextImage", while you're calling setMask on mc before it's created. but maybe i didn't glance hard enough.
0
mkofahlAuthor Commented:
Hmmm, that could be an issue. But it seems that i doesn't work, no matter where I call setMask.

When I do a trace on mc- it comes up with: "_level0.img3", does that mean it's not on _root but _level0 instead? The mask that I'm using is a square MovieClip  on the canvas, with the instance name of "mask_mc". The only thing I can think of is perhaps mc is on a different level to mask_mc.

Does that make sense?

I can attach the .fla if that would help.


Thanks
0
najhCommented:
I don't think the fla will help me much as I use flash 8 and AS2, although the principles here should be much the same.

_level0 and _root should direct you to the same level (in AS2).

I seem to recall that there isn't a _root in AS3 though, but a Stage and maybe a non-underscored root.
Hmm I'm not sure that helps, but it's where my thinking is currently on your issue...

I also found a reference to such root based discussions here:
http://www.actionscript.org/forums/archive/index.php3/t-121003.html


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mkofahlAuthor Commented:
Sorry for the late reply.

Although I'm using CS3, I'm outputting the swf to flash 7, with AS2.
Does that change anything?

Thanks again for your help.
0
mkofahlAuthor Commented:
Any progress made with this issue?

It would be great if there was a solution to this problem.
0
mkofahlAuthor Commented:
Thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.