Bobspace – Bob Walton

Flash: Mixing Run-time elements with author time-masks

October 16, 2006 · 8 Comments

Like I mentioned in my earlier post, I’ve been working on a large project that has a lot of AS2 mixed with densely layered FLAs, full of author-time elements.

I ran across an interesting nuance in masking, while trying to mask a run-time MovieClip, with a mask that was created in author-time.

Here it is:

Making an object in run-time and then calling its setMask and passing in an author-time movieClip will unmask whatever the author-time movieclip was previously masking.

There are a couple of ways around this problem:

1. Create an empty “holder” MovieClip, in author-time (you know, on the stage) and make sure it is being masked. Then, attach your run-time MovieClip to that holder instance. Problem solved.

2. You can also duplicate the mask using duplicateMovieClip and call setMask on your run-time MovieClip and pass in your new mask as the argument.

Still with me? Check out this example, it’s way less confusing.

Neither approach is terribly elegant, but if you’re mixing author-time and run-time elements, there’s bound to be some non-elegant-ness anyway.

You might be thinking, “Hey, I’m a coder. Why would I bother with an author-time mask, anyway? I’d rather make one in code and then use it how I please.” I hear ya.

When I was presented with this problem, I had a mask, created in the Flash IDE that was masking dozens of layers, with a complex animation and functioning perfectly. All it needed was one or two run-time elements to be behind the mask. At that point, it’s not worth the trouble to recreate the mask, with its crazy animation, in code, just to pull one or two things under it.

When developing in Flash, especially when designers and developers of varying skill levels are contributing code, these situations will come up. Sometimes, you just gotta hack.

Categories: Flash and Flex

8 responses so far ↓

  • Unisda // March 12, 2007 at 6:18 pm

    hey, i was mighty chuffed to come across your site, i developed this thing that loads movies at runtime using duplicateMovieClip and i then realised after many hours of work, that i now can’t mask them. I’m having a look at what you did now, see if i can figure it out. any tips, pls mail me.
    uni.

  • Bob Walton // March 12, 2007 at 7:06 pm

    Hmm… For one othing, is there any reason you’re using duplicateMovieClip instead of attachMovie?

  • Unisda // March 12, 2007 at 7:20 pm

    i have a clip on the stage intially, and then based on results returned from the database, it duplicates the required amount of times, and loads images and text into it. but now when there’s more then 3 items, i need to mask it and scroll.
    i’ve tried your examples, using the loader and attaching a clip into the holder, but it still doesn’t mask the other guys.

  • Bob Walton // March 12, 2007 at 7:53 pm

    First of all, the duplicateMovieClip technique you are using is way old-skool and prone to some disadvantages. I would add that MC to your library, give it a linkage ID, and add it to the stage using attachMovie. If you’ve never tried this before, take the time to figure it out. It’ll blow your mind.

    If you’re using classes, that’s the best way to mate object-oriented functionality to your MovieClip. It’s also waaaay cleaner.

    But enough about that. Along with TextFields, masks are among the most tempermental elements in flash to work with. There could be a multitude of reasons why it’s not working, in your case.

    If you can distill your problem to its most simple case and email it to me, I’ll try to take a glance at it.

  • Unisda // March 13, 2007 at 9:21 am

    if you have the time, i’d appreciate it.
    i tried attaching the clip, and then attaching a mask into the holder on the mask layer, but does that mean for each subsequent clip i attach (based on loadVars) i have to attach another mask for it.

    i’m not going to send u the stuff cause u’ll need all the php scripts, but is it possible to, in a for loop, attach the initial clip, and attach it x number of times, reposition them, attach 1 mask in the holder and have it mask all of them?

    thanks for your thoughts.

  • Bob Walton // March 14, 2007 at 8:38 pm

    Create an empty MovieClip and attach all of your content to it. Then set the mask of that single, container MovieClip.

  • Unisda // March 23, 2007 at 6:04 pm

    hey i’m back. tell me, if i’m using loadMovie to load images from the harddrive, is there a way to dynamically mask them – and if the mask is an animation, tweened – is this possible?

  • Jan // December 12, 2008 at 5:44 pm

    Hi Bob,I am trying to duplicate a movie clip as a mask and found your site. Your link to the example doesn’t work, any chance you can put it back up?
    thanks!

Leave a Comment