# Generating hitArea programmatically from BitmapData

**URL:** <https://forum.kirupa.com/t/generating-hitarea-programmatically-from-bitmapdata/240115>\
**Category:** Uncategorized\
**Created:** [September 29, 2007, 7:39am UTC](https://forum.kirupa.com/t/generating-hitarea-programmatically-from-bitmapdata/240115 "2007-09-29T07:39:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovapaglia](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@giovapaglia](https://forum.kirupa.com/u/giovapaglia)\
**Post date:** [September 29, 2007, 7:39am UTC](https://forum.kirupa.com/t/generating-hitarea-programmatically-from-bitmapdata/240115/1 "2007-09-29T07:39:52Z")

</div>

How can I create a complex hitArea for a Sprite  
starting from alphachannel data of a dynamically loaded image?

Either  
If I apply the image (wrapped in a Sprite) as the hitArea  
or  
If I apply the image as a simple mask

mousevents gets triggered in the rectangular area  
that has the dimension of the loaded image.

In the authoring environment solution is simple…

- take the image
- do a trace bitmap
- use the traced bitmap as hitArea in a SimpleButton.

It’s in ActionScript that I’m having problems…  
I think that’s because I’m still working  
with the BitmapData of the image (that is rectangular)  
But how can I obtain a Shape from the alphachannel data  
of the image I loaded?  
The idea is to use this arbitrarily complex Shape  
(wrapped in a Sprite) as a dynamically generated hitArea?

Have you ever tried something like that?  
Is that even possible?  
Using Actionscript shouldn’t I have access to all that  
could be done in the authoring environment?

Any suggestions  
Thanks  
Jo
