views:

35

answers:

3

I have a textfield inside a rectangle (Sprite). The text fits inside the rectangle just fine, however the actual size of the textfield is larger than that of the sprite. (invisible top margin in the font)

The problem is when I added an eventlistener to the Sprite that detects mouse clicks, it fires even when I click outside of the rectangle. How can I fix this? (so that child object size does not exceed parent size)

A: 
sprite.mouseChildren=false

and maybe you need to use textfield.selectable=false too.

textField too high and widde? change to

textfield.width=textfield.texhWidth, textfield.height=textfield.textHeight
Hwang
this doesn't work
simon
why do you need your text to exceed the size of the sprite?can set the text.width=text.textWidth+2, and text.height=text.textHeight (add few points cause sometimes it will crop a bit of the letter)
Hwang
I'm guessing he would rather not affect the display of the text field.
Matt W
A: 

If the rectangle isn't a Sprite or MovieClip iteself, convert it to one so that within a container Sprite you have the rectangle and the text field above it. Give the rectangle an instance name of 'base'. First, like Hwang said, set the mouseChildren property of the container to false. After that set the hitArea property of the container equal to the rectangle. It would look something like this:

container.mouseChildren = false;
container.hitArea = container.base;
Matt W
A: 

Random guess, maybe applying a mask to the sprite will fix this.

var mask:Shape = new Shape();
mask.graphics.beginFill(0);
mask.graphics.drawRect(0,0,recWidth,recHeight);
sprite.addChild(mask);
sprite.mask = mask;
Bart van Heukelom