Stick Page Forums Archive

Legit Alpha Gradient Masking Without Actionscript [Flash][Effects]

Started by: Jeff | Replies: 16 | Views: 36,875

Jeff
Administrator
1

Posts: 4,356
Joined: Dec 2007
Rep: 10

View Profile
Oct 23, 2012 4:51 AM #766792



















[table="width: 200, class: outer_border, align: left"]
Tutorial Content
1. The Problem
2. A Solution
3. The Solution
4. Examples





Legit Alpha Gradient Masking Without Actionscript

So this is something that's bugged me for a while. I remember being able to have an alpha gradient as a mask in earlier versions of flash, so that I could take a solid object and make parts of it more or less transparent depending on the mask, but a few years ago when I tried to do this it wouldn't work right, and no one I talked to could tell me how to do it the proper way. Everyone said that they knew it could be done, but wasn't sure how. Well, recently I took it upon myself to do some research and rediscover this long lost technique, and it's fairly simple, so I've decided to make a small tutorial to share with you today.


[/table]

1. The Problem

Now, a regular mask involves 2 layers. One layer is the shape that's getting masked, and the other layer is the mask itself that will show/hide parts of the shape beneath it depending on where the mask's shapes are. That looks like this:

Image


Notice the layers showing which is the mask and which is going to get masked. On the stage, we see the big red area which will be what content is shown, and we see the text that is to bed masked. When the mask is applied, it looks like this:

Image


See how the part of the text that was covered by the big red box in the previous image is now showing, whereas the rest is hidden? This is because the big red box is "masking" the text to only show where I want it to as defined by the box itself. To further illustrate this, say I want to make the text polka-dotted:

ImageImage


Now, this is useful for certain applications, but say I want to have a soft edge to the mask, so that it looks like it's fading in. You'd think I could just make a gradient on the mask and be done with it right? Well let's try that:

Image


So this LOOKS like the end result will have a nice smooth transition for the text from solid black to completely transparent, right? Here's how it actually looks when the mask is applied:

Image


So what happened? Where's our nice fading effect on the text? Well, the way these masks work is based on the SHAPE of the mask, and not the color or transparency. The mask will be applied wherever there is a shape. For example, this image has a striped mask on it, but I made it 100% transparent so you can't see it:

Image


When the mask is applied, you can see it, even though it looks like there is nothing there:

Image



2. A Solution

So how do we get the desired effect? Well, a lot of people will simply make a solid gradient over top of what they want to mask if the background is a solid color. So for example, the background of my project is white, so I could make a white to transparent gradient box and position it over the text like so:

Image


This looks OK, and creates the desired effect simply. But it's not a mask, and it's a cheap workaround. What if I had a wacky and complicated background?

Image


That white gradient is no longer sufficient. So now what can we do?


3. The Solution

The solution is deceptively simple, and has to do with movieclip blending. So far in my project I have 2 layers: The Background, and The Text:

Image


I want to mask the text so that it fades from solid to transparent. So my first step is to draw the mask. This can be on the same layer as the text, or on a new layer above it. Doesn't matter, but keep them close for convenience during a later step.

Image


Turn the mask shape into a movie clip. Call it what you want, I'm going to call mine theMask.

Image


Select your Mask Movieclip, go to it's Properties and set it's Blending to Alpha.

Image


It will vanish. This is normal. Next, select both the newly created mask movieclip, and the object you want masked (in this case, the text) and put them both into their own movie clip. I'm going to call my movieclip theContainer.

Image


Once created, set your container movie clip's blending to Layer, and voila:

Image


The mask is applied, fading out regardless of what is in the background.

Image


This can be used to achieve a reflective effect, regardless of background:

Image



4. Examples

The effect used with animation: http://filz.us/3nL

Also used as a reflective effect: http://filz.us/3nM

Or simple shadows: http://filz.us/3nQ

If you have any questions or need any clarification, please let me know!
Jomm

Posts: 35
Joined: Feb 2012
Rep: 10

View Profile
Oct 23, 2012 5:06 AM #766807
IT... IT WORKS OMG O_O PRAISE JEFF OMG. -praises-
Xero
2

Posts: 7,563
Joined: Feb 2012
Rep: 10

View Profile
Oct 23, 2012 5:18 AM #766818
I actually managed to stumble across this technique when experimenting with filters but thought nothing of it at the time.
Later I needed it but couldn't retrace my steps far enough to remember how it was done.
Thanks jeff.
Edit: nevermind, what I did was different but similar. I wish I remembered what it was.
S.A.

Posts: 942
Joined: Feb 2012
Rep: 10

View Profile
Oct 23, 2012 5:30 AM #766822
Oh really nice reflection effect. So that's what you used in your signature?
Scarecrow
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Oct 23, 2012 5:45 AM #766832
huh, neat. good find
mx
2

Posts: 495
Joined: Feb 2012
Rep: 10

View Profile
Oct 23, 2012 9:43 AM #766925
WHAT THE FUCK IS THIS SORCERY.
Salt
2

Posts: 5,455
Joined: Jun 2012
Rep: 10

View Profile
Oct 23, 2012 11:12 AM #766965
or a simpler way, make the gradient the object and make the text the mask, simple, right? but the gradient has to be in the color of the text you're looking for.
Pepper
2

Posts: 74
Joined: Feb 2012
Rep: 10

View Profile
Oct 23, 2012 1:04 PM #767019
Quote from Ahmad9383
or a simpler way, make the gradient the object and make the text the mask, simple, right? but the gradient has to be in the color of the text you're looking for.

Jeff's method is simple, and I can't understand what you're suggesting. if you have a changing background, this is really the key way to do it.
Shensurei
2

Posts: 3,395
Joined: Feb 2012
Rep: 10

View Profile
Oct 23, 2012 1:07 PM #767022
Does this still work alright if the movie clip is animated?
Smile
2

Posts: 5,331
Joined: Jan 2012
Rep: 10

View Profile
Oct 23, 2012 2:57 PM #767082
Quote from Ahmad9383
or a simpler way, make the gradient the object and make the text the mask, simple, right? but the gradient has to be in the color of the text you're looking for.


that won't work with a complex, colored background. I did what I BELIEVED you said, and it failed.

Quote from Shensurei
Does this still work alright if the movie clip is animated?


I tried to use it on an animation and it worked. Inside "theContainer", I made an animation in a different layer from "theMask". The layer where "theMask" is placed will be on top of the layer for the animation. The frame will go the length of the entire animation.

example result: http://www.fileize.com/view/b5fc5d82-a6d/


Not sure if this answers your question tho since idfk what movie clip you're referring to.
Jeff
Administrator
1

Posts: 4,356
Joined: Dec 2007
Rep: 10

View Profile
Oct 23, 2012 3:56 PM #767110
Quote from Ahmad9383
or a simpler way, make the gradient the object and make the text the mask, simple, right? but the gradient has to be in the color of the text you're looking for.


I get what you're saying, and this is another way to do it, but it also has it's limitations just like the other alternate methods. What he's saying is, the text becomes the mask and the gradient will color under the mask, like so:

ImageImage

But if you want to do any coloring or use complex shapes, this method doesn't work at all. Say I have this shape:

Image

Using your method just doesn't work:

ImageImage

Because the shape is still the mask, and the mask is ignoring colors. Using my method gets the desired effect quickly:

Image

Quote from Shensurei
Does this still work alright if the movie clip is animated?


As long as the container movieclip has a blending of Layer, and the topmost movieclip inside the container is a mask with blending alpha, you'll get the desired effect, regardless of animation, layers, color, whatever.

For example: http://filz.us/3nL

Also used as a reflective effect:

http://filz.us/3nM

Or simple shadows:

http://filz.us/3nQ
stone

Posts: 1,959
Joined: Mar 2008
Rep: 10

View Profile
Oct 23, 2012 7:59 PM #767275
Jeff, this is excellent man! I encourage all flash users to have masking in their tool belt. It comes in handy in many different situations throughout animation and game development.
Snuggz

Posts: 161
Joined: Sep 2012
Rep: 10

View Profile
Oct 26, 2012 5:57 AM #769452
oh i see
Externus
2

Posts: 673
Joined: Feb 2013
Rep: 10

View Profile
Aug 16, 2015 9:23 PM #1396368
FOUND IT. THIS THING IS GOD.
Spectre
2

Posts: 870
Joined: Jan 2013
Rep: 10

View Profile
Aug 17, 2015 12:44 PM #1396485
Quote from Externus
FOUND IT. THIS THING IS GOD.


This crap is actually incredible. I find myself referring to it every month or so atleast.
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.