[Webinar] Streamline your web hosting managementRegister Today

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

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

0
mkofahl
Asked:
mkofahl
  • 4
  • 2
1 Solution
 
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
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.
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

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