?
Solved

Flash AS3 CacheAsBitmap problem when masking

Posted on 2011-03-19
7
Medium Priority
?
1,176 Views
Last Modified: 2012-05-11
Hi all,

This one has really got me - if there is an answer then it's definitely worth more than 500 points!

I have two movieclips, both dynamically generated. One is to be used as a mask for the other. The clip to be masked is rectangular in shape and the clip doing the masking is a parallelogram. The mask is dynamically resized so has 9-slice scaling enabled to ensure its angled edges remain intact. Nothing out of the ordinary so far.

The first problem that had to be overcome was that a movieclip distorts and ignores the 9-slice-scaling when its used as a mask. I used the CacheAsBitmap and nesting trick I found here to fix this problem: http://www.kirupa.com/forum/showthread.php?t=334533

So, everything looks perfect at this point.

Now, here's the hard part. The hit area of the masked clip is behaving like it has been masked by the distorted mask, not the beautifully 9-slice-scaled mask! SO, to recap, the movieclip displays exactly as planned on the stage once masked, but its invisible hit area behaves as though it has been masked by a non-9-slice-scaled, distorted version of the masking clip!

I have been staring at my screen for 4 straight hours - PLEASE HELP!
0
Comment
Question by:courtthree
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35173922
I would like to see the scenario, can you share your snippet. It will be easier to suggest.

Warm Regards
Deepanjan Das
0
 
LVL 6

Author Comment

by:courtthree
ID: 35174710
I don't know if this will help much but the function that applies the mask (it's reusable by several clips) is pasted below. "inner" is the 9-sliced mc inside the masking clip that gets resized...
private function angleMask(mcClipParent:MovieClip, mcClipToMask:MovieClip, nX:Number, nY:Number, nW:Number, nH:Number, maskType:Class) {
			var newMask:MovieClip = new maskType();
			mcClipParent.addChild(newMask);
			newMask.x = nX;
			newMask.y = nY;
			newMask.inner.width = nW - 200;
			newMask.inner.height = nH;
			newMask.cacheAsBitmap = true;
			mcClipToMask.cacheAsBitmap = true;
			mcClipToMask.mask = newMask;
		}

Open in new window

0
 
LVL 6

Author Comment

by:courtthree
ID: 35174716
Adendum: The "void" is missing on the above. It exists in my actual code.
0
 
LVL 3

Accepted Solution

by:
James Tomasino earned 2000 total points
ID: 35233073
I'd suggest using a non-standard hittest. I've run into a handful of problems with advanced masks in Flash, like the 20x scaling of duplicated bitmap masks, and this very one. Luckily, plenty of folks have made great hittest functionality that you can use to get around the built-in Flash methods. I'd recommend Grant Skinner's pixel perfect hit test. There's a few versions out there, but the latest I remember seeing was updated by Troy Gilbert (http://troygilbert.com/2009/08/pixel-perfect-collision-detection-revisited/). This will take a little work to implement if you want to use the class natively, as it assumes hit tests between two objects, not an object and the mouse. You could, I suppose, create an invisible pixel-sized object that gets assigned to the mouse x & y upon a click before running the test. It's a bit of a hack, but hopefully this method will work better for you. Good luck.
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 36978229
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may or may not be familiar with Kodi (http://www.kodi.tv) the open source software media player and entertainment hub that can be installed on Linux, OSX, Windows, iOS, and Android.  Kodi which started off as X-Box Media Center (XBMC) many years…
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question