Solved

Flash AS3 CacheAsBitmap problem when masking

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn how to include realistic velocity sensitivity to their Sampler instruments. Set the Vol<Vel parameter in the Filter/Global tab to your desired setting: Gather samples of hits of various intensity, and drag/drop into Velocity zon…
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 …

749 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