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
Solved

Flash AS3 CacheAsBitmap problem when masking

Posted on 2011-03-19
7
1,156 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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Tired of waiting for your show or movie to load?  Are buffering issues a constant problem with your internet connection?  Check this article out to see if these simple adjustments are the solution for you.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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