Solved

Flash AS3 CacheAsBitmap problem when masking

Posted on 2011-03-19
7
1,136 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
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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now