View Full Version : use bounding box for mouse interaction
GrndMasterFlash
September 12th, 2008, 12:57 PM
im only asking cause i feel lazy and don't want to have to look it up or spend too much time thinking about it, soo
does anyone know of an easy way to use the bounding box of a MC instead of the contents for say clicking and dragging ***without adding any extra invisible graphic***
i have an array of words that i want to turn into buttons, i know i can add an invisiable box but it just seems like there should be an easier way, any ideas?
and yes i am feeling lazy today :z:
creatify
September 12th, 2008, 01:00 PM
you can dynamically draw that box and assign it to the hitArea property of your button clip:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html#hitArea
GrndMasterFlash
September 12th, 2008, 02:44 PM
***without adding any extra invisible graphic***
i have an array of words that i want to turn into buttons, i know i can add an invisiable box but it just seems like there should be an easier way, any ideas?
and yes i am feeling lazy today :z:
...
skineh
September 12th, 2008, 02:56 PM
...
rofl, that was my thought as well
Only thing I can think of off the top of my head is giving the text field a background color. If the words are all sitting in front of a solid color (such as the stage), then you could just set the text fields' background colors to the same color - your hit area is now the bounding box, and the user won't notice/realize it has a background.
EDIT - unless of course there's other stuff in your MC other than the word. :P Sry for the scatterbraining, I have a bigass hurricane bearing down on me.
GrndMasterFlash
September 12th, 2008, 03:15 PM
pretty clever but it would show when you drag one word over the other.
right now im just using the old invis box cause it works, but i would still like to hear more solutions to this question as it seems rediculous to draw a box then add it as a child when all i want is a solid clickable area...
more ideas plz :D
skineh
September 12th, 2008, 03:27 PM
Just need to get CS4 to accept 32-bit colors for text field backgrounds. A .001 alpha fill works in a pinch for a lot of situations.
Anyways, that was my clever idea for the day. Someone else think up something.
Obviously, you could just convert the textfields to bitmaps but that's just as much effort (if not a smidge more) than putting in a shape. :P
creatify
September 12th, 2008, 03:59 PM
haha - I thought I would get the "read my post again!" message. I really don't think there is a more effiecient way to do that besides setting up a textbutton class that handles that then going forward, you just have to instantiate instances of your custom class vs. adding the extra line of creating/assigning a sprite.
just ran a test - how are you setting up your buttons? The following does register events for me, even when the mouse is over dead spots within textField - it appears to be utilizing the actual textField bounding box?
var tf:TextField = new TextField();
tf.width = 100;
tf.height = 20;
tf.embedFonts = true;
tf.selectable = false;
tf.text = "This is my text";
tf.autoSize = "left";
var tfo:TextFormat = new TextFormat();
//I embedded this font into my library
tfo.font = "ATSackers Heavy Gothic";
tfo.size = 20;
tfo.color = 0x000000;
tf.setTextFormat(tfo);
addChild(tf);
tf.addEventListener(MouseEvent.CLICK, foo);
tf.addEventListener(MouseEvent.MOUSE_OVER, o);
tf.addEventListener(MouseEvent.MOUSE_OUT, ot);
function foo(e:MouseEvent):void {
trace("click")
}
function o(e:MouseEvent):void {
e.target.alpha = .5;
}
function ot(e:MouseEvent):void {
e.target.alpha = 1;
}
GrndMasterFlash
September 12th, 2008, 04:34 PM
ceratify thank you for the much more insightful answer, i ended up just drawing invisible boxes even though it seems there would be a better way.
i will give you class a try though, you seem to be onto the right idea, good show ol' chap! i'll have to put it in and test it, thanx ;)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.