[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4140
  • Last Modified:

Adding a mask using Actionscript?


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:


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

Any ideas?

//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
// 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]);
                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);
        this.lastNum = num;
       // trace("current num:" + num);
        return num;
function LoadNextImage() {
        // clear the interval if any
        //specify random conditions
        var imageNum:Number = generateRandom(1, 7);
        // get the first image
        var imageName:String = "http://mydomain.com.au/flash/images/" + "" + imageNum + ".jpg";
        // 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("mc: " + mc);
// Start everything

Open in new window

  • 4
  • 2
1 Solution
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.
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.

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:

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
mkofahlAuthor Commented:
Any progress made with this issue?

It would be great if there was a solution to this problem.
mkofahlAuthor Commented:
Thanks for your help

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now