I have a textfield inside a rectangle (Sprite). The text fits inside the rectangle just f开发者_如何学Pythonine, 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)
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;
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;
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
精彩评论