PDA

View Full Version : Custom Shape



hairyharry
August 26th, 2008, 12:38 PM
hey let me say i really enjoy the site and the forum...some great info on here
______

my question is this: i want to import a custom image as a mc so when you click on it something happens...like:

mc.addEventListener(MouseEvent.CLICK, hit);
function hit(e:MouseEvent):void{
trace("CLICKED");
}

the problem is when i import the image as a mc the "clickable" area is a sqare but i want it to be just the shape itself - it's a complex shape so i can't draw it in flash...comprendo? thanks in advance

snickelfritz
August 26th, 2008, 02:49 PM
Try copy/pasting the object from Illustrator.
This usually yields an object in which only the filled areas are targets.
ie: there is no mask or invisible bounding box trapping events.

Photoshop png24 and PSD have a 24bit transparency mask that is pixel data, so it has a bounding box in Flash.
Pixel-based images require bounding boxes for various reasons.
Text and vector art do not necessarily require a bounding box.

hairyharry
August 26th, 2008, 09:13 PM
thank you, unfortunately i don't have illustrator...good advice though and youve given me some good key words for a search - i've found a bit already here if anyone's interested...

https://www.mochiads.com/community/forum/topic/non-bounding-box-hittest-any-good-tutorials-as3

not quite what i was looking for but it's a start- i can't believe how little i've found on the subject though, it seems like it would be a more common problem?...does anyone have any other suggestions or any other places to look? thanks again

snickelfritz
August 26th, 2008, 09:46 PM
Select the bitmap and press F8: name it bitmap_mc", and give it an instance name of "bitmap_mc".
Press F8 again: name the movieclip "bitmapContainer";
Open bitmapContainer in edit mode.
Now, use the pen tool in Flash to trace a "hit" area on a new layer above "bitmap_mc".
You are just tracing the rough contour of the visible objects in the image; it doesn't have to be perfect.
Convert the path to a shape.
Select the shape and press F8; name it "hit_mc", and give it an instance name of "hit_mc".

Create a locked actions layer in bitmapContainer.
(you should now have three layers in bitmapContainer: bitmap_mc, hit_mc, actions)
Paste this script.

this.mouseEnabled = false;
hit_mc.buttonMode = true;
bitmap_mc.mouseEnabled = false;

var btnName:String = "";

this.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
this.addEventListener(MouseEvent.MOUSE_OUT, btnOut);

function btnOver(event:MouseEvent):void
{
btnName = event.target.name;
trace("mouse is over " + btnName);
}

function btnOut(event:MouseEvent):void
{
btnName = event.target.name;
trace("mouse is off " + btnName);
}


This script will allow you to easily test the hit area, which should work if you followed the instructions.
GL

hairyharry
August 26th, 2008, 10:08 PM
exactly the type of solution i was looking for - it looks straight forward i'll give it a test run...muchas gracias