Thursday, August 11, 2005

Alpha masking goodness in Flash Player 8

A while back when we started implementing the cache as bitmap functionality in the Flash Player I was tasked to make masks work with it. The initial implementation was simply doing edge based masking and behaved like you think Flash should behave. What is edge based masking? It means that the vectors of the mask and masquee are intersected before they are drawn to obtain the cutout which is a vector shape in itself. That's why alpha masking was not easily possible technically in previous Flash Player versions since there is no pixel level interaction at this level between mask and masquee. Now, and so it happened a few times during this release, I stared at the code and told myself: Alpha masks are now trivial to implement with the bitmap caching! A couple of hours later it was done.

So how do you make it work? Mask and masquee have to be both movie clips and need to have the cacheAsBitmap flag set. Now you can simply do a setMask() and that is it. The only sad part about this is that due to time constraints there was simply no time to add this to the authoring tool for easy access. But, the good news is that designers will only need one line of code to make it work. Hence the example I posted here. Softwipe goodness! You can't tell me that this is not beautiful! This movie has only one line of code, the rest are simple tweens on the timeline:

mc1.setMask(mc2)

33 Comments:

Blogger matt said...

gradient masking? Is this only possible with cache as bitmap?

Friday, August 12, 2005 4:00:00 AM  
Blogger Alain Duchesneau said...

Hi!

will it be possible to use a video with 8bit alpha as a mask?
Imagine the possibilities!!

Thursday, August 18, 2005 7:26:00 AM  
Anonymous Anonymous said...

I would very much like to know the answer to the previous question. Masking with alpha video would really double what you could do with video.

Monday, August 29, 2005 7:30:00 AM  
Anonymous Anonymous said...

Answer to above: yes. Bitmap cacheing doesn't care whether it's compositing vectors, video, or bitmaps.

Thursday, September 01, 2005 3:16:00 AM  
Anonymous Richard Lyall said...

Love the effect ...

Could you provide some more info about how to construct this?

Might it be possible to see a sample FLA file that demonstrates this in action?

Sunday, September 25, 2005 2:59:00 PM  
Anonymous Anonymous said...

it's simple (and fantastic):

3 layers: "Actions", "Mask"(ie: picture_a), "Whats being Masked" (ie: picture_b).

mc1 = instance name of movieclip - "picture_b"

mc2 = instance name of (the mask) - movieclip - "picture_a"

On the actions layer:

mc2.cacheAsBitmap = true;
mc1.cacheAsBitmap = true;
mc1.setMask(mc2);

done.

Monday, September 26, 2005 9:18:00 PM  
Blogger Richard Lyall said...

Thanks for that. Have done what you suggested, I can't get it working (I am new to Flash).

Problem might be with the resources I'm using. Does this require images with Alpha channels like PNGs, or movies with Alpha channels?

Can this effect be created with native Flash objects?

Thanks again
Richard

Friday, September 30, 2005 3:11:00 PM  
Blogger Matt said...

There was a workaround to create soft wipe effects prior to Flash 8 - but it is not nearly as flexible as this will be. It was ; create an alpha channel in a PNG, and then use Colour Transform to modify the alpha values up and down.

Monday, December 12, 2005 6:57:00 AM  
Anonymous Collis said...

Hey Richard, yep just make the top image (the one doing the masking) a PNG file with a gradient going to nothing (i.e. transparency). Put that in a movie clip with (or without) an animation making it move along and then use that as the masker with some random image as the maskee.

boy i never realised how much harder it is to describe these things than to actually do them!

Anyhow well done on having this new feature and surprisingly it doesn't seem to slow my flash player down either, hurrah!

Monday, January 09, 2006 4:19:00 AM  
Anonymous Collis said...

actually just realised that it doesn't even need to be a PNG with transparency, just make a big rectangle with a gradient fill going to 0 opacity. hurrah!

Monday, January 09, 2006 4:24:00 AM  
Anonymous Anonymous said...

Umm ... what is the effect? All I see is an image of a flower. Nothing is animated.

Tuesday, January 10, 2006 5:32:00 AM  
Anonymous Anonymous said...

I have a problem with setMask(). I can get it working, and it's great, BUT! when another movieclip passes over it, the masking seems to behave strangely, as in: either the mask only applyes to where it's completly opaque, leaving the semytransparent pixels invisible, or it seems to apply the mask multyple times, shrinking the visible region. My maskee is a mc containing multyple nested mc's, and the mask is a simple gradient fill (Alpha 100 -> Alpha 0).

Also, jfor those interested, you can use any combination of [vectorial drawings], [images w/ or without transparency (alpha channel)] and [movies (altough i haven't personally tested with them yet)] as both mask ad maskee.

PS: anonymous, you probably have flash version 7, get the version 8 to see and use the new effects on that example.

Monday, February 06, 2006 1:16:00 AM  
Anonymous Tony said...

If anyone can help me out, I'd GREATLY APPRECIATE IT. I can't figure out how to animate this. Can someone please, please make a simple tutorial for this?

Thanks a bunch

Thursday, March 09, 2006 9:18:00 PM  
Anonymous Tony said...

actually I got it guys:

http://www.gotoandlearn.com/

thanks though!

Friday, March 10, 2006 5:02:00 PM  
Anonymous Anonymous said...

that's awesome, but how do you do it? can we see the fla?

thanks!
chad

Thursday, August 17, 2006 12:00:00 PM  
Anonymous Tamori said...

Unfortunately, gradient alpha masking using this technique doesn't work if the mask and maskee are embedded inside a movieclip or an external SWF file and that movieclip/SWF is added to the main scene. In that case, the mask is simply not applied and both elements appear as solid objects.

Thursday, September 28, 2006 10:19:00 PM  
Anonymous Anonymous said...

is there no workaround for that?

Thursday, October 05, 2006 11:55:00 AM  
Anonymous Anonymous said...

I dont think this last comment is correct. I just got it working with animated mask attached to a movieclip on the stage (not attached to root itself) and with it masking a loaded jpg

just make sure you have cacheAsBitmap turned on for the right mcs

Monday, October 23, 2006 8:01:00 PM  
Blogger dandin1 said...

In Flash Professional 8, using cacheAsBitmap in a script just makes a boring non-alpha mask. But clicking the "use runtime bitmap caching" in the properties pane works.

Tuesday, December 19, 2006 4:16:00 PM  
Anonymous Cindy said...

Does anyone know how to get this to work with the same mask being applied to multiple layers (MCs) inside the same .fla file?

Also, I'd like to use the alpha bitmap mask in different spots along the timeline. Works the first time it's called, but then later in the timeline when it comes upon the same mask (even with a different instance name), it just shows it as a bitmap and it doesn't behave as an alpha bitmap mask.

Monday, March 19, 2007 11:39:00 AM  
Blogger Daniel said...

The key to making the video masking of other content work is that the video used as the mask in the .setMask(x) function must be a movie clip object not a video object. All you need to do is put the video inside a movieclip and you're set. Works in Flash Pro 8.

Saturday, July 07, 2007 12:26:00 PM  
Anonymous Anonymous said...

it's a pitty that it's buggy... :( i've used alpha masking a lot in my current project, the thing is that if there's a layer in masked mc having tween, you stop the movie in that frame and cause flash to repaint then the mask fails to work properly.

in my case, i'm doing animation engine and transitions are alpha mask based - if i stop the current animation at phase where animation is playing or in worst case i don't stop the animation inside of maskee then my maskee get's transparent in areas where it's not supposed to be like that. this is caused by cache as bitmap i guess, but it's a pitty when you run into the situation that you cannot workaround...

Wednesday, July 25, 2007 5:42:00 PM  
Anonymous Anonymous said...

Very helpful info. Thought I should give something back to anyone that's still having problems. The problem I had was that I was not naming the movie clips in the properties toolbar. I assumed that naming the movie clips when I created them was enough. Also make sure the names you enter into the action script are exactly as they appear in the properties toolbar for each movie clip as it's case sensitive.

Sunday, August 05, 2007 6:30:00 PM  
Anonymous <a href="http://m1.aol.com/phentermine4">Phentermine</a> said...

Great Article! Thank You!

Tuesday, August 28, 2007 2:51:00 PM  
Anonymous <a href="http://m1.aol.com/phentermine4">Buy Phentermine</a> said...

Thanks to author! I like articles like this, very interesting.

Wednesday, August 29, 2007 2:22:00 AM  
Anonymous <a href="http://free-metro-pcs-ringtones.blogspot.com">Free Ringtones</a> said...

nice blog!

Sunday, September 02, 2007 10:59:00 AM  
Anonymous <a href="http://buy-viagra2007.blogspot.com">buy viagra</a> said...

nice blog!Nice information

Monday, September 03, 2007 2:13:00 PM  
Anonymous <a href="http://buy-levitra--ooz.blogspot.com">Levitra</a> said...

:-) ochen\' zaebatyj blog!

Tuesday, September 04, 2007 2:12:00 AM  
Anonymous <a href="http://buy-soma--ooz.blogspot.com">Buy Soma</a> said...

soglasen s vami ochen\' zaebatyj blog!

Thursday, September 06, 2007 2:52:00 AM  
Anonymous <a href="http://search.cnn.com/search?query=site:cialis-online-2007.blogspot.com?cialis_online.html">Anonymous</a> said...

Keep up the great work. It very impressive. Enjoyed the visit!

Sunday, September 09, 2007 1:27:00 PM  
Anonymous Anonymous said...

Hello,
could anybody tell me why is this wrong :
http://students.ceid.upatras.gr/~georgiu/test.fla

testing only the mc that contains the effect show that it is working

Monday, October 15, 2007 7:09:00 AM  
Anonymous Anonymous said...

You completely stuffed up the alpha channel process. In "ALL" other applications, an alpha chanel is a gradient with pixel information between white and black. In your script, you have to have information between transparent and black. It confuses people. Alpha channels should always be grayscale maps.

Saturday, November 10, 2007 5:29:00 PM  
OpenID mcsfloridamike said...

I just tried this with a scrolling text box that is only supposed to show between the top and bottom slider arrows, and it worked famously. Thanks for the tip!

Wednesday, May 21, 2008 1:46:00 PM  

Post a Comment

<< Home