2015-08-14 5 views
0

У меня проблема. Я сузился до своего класса кнопок, где, если я нажимаю 50-100 пикселей ниже области спрайта, запускается прослушиватель событий mouse.click.as3 кнопка щелкнув 50 пикселей ниже кнопка

В какой-то момент я подумал, что вложенная проблема с детьми спрайтов может вызвать ее, но даже добавление кнопки прямо к сцене имеет тот же эффект.

Я переписал класс кнопки с нуля и то же самое произошло. Я не уверен, что это то, что происходит, потому что я пишу чистый as3 с фрейм-каркасом или чем-то еще. Вот класс для кода кнопки:

package org.project.ui 
{ 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.display.Graphics; 
import flash.text.TextField; 
import flash.text.TextFormat; 
import flash.text.TextFormatAlign; 
import flash.display.Shape; 
import flash.display.SimpleButton; 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.text.TextField; 
import flash.text.TextFormat; 
import flash.text.TextFormatAlign; 
import org.project.controller.IController; 
import flash.utils.getQualifiedClassName; 
/** 
* 
* 
*/ 
public class CustomButton2 extends CustomSprite 
{ 
    protected var _button:Sprite; 
    protected var _buttonFunction:Function = null; 
    protected var _label:String = ""; 

    protected var _textField:TextField; 
    protected var _textFormat:TextFormat; 
    protected var _font:String = "Arial"; 
    protected var _fontSize:int = 12; 
    protected var _fontColor:uint = 0x000000; 

    protected var _buttonWidth:int = 110; 
    protected var _buttonHeight:int = 30; 

    public function CustomButton2(label:String, id:String, w:int, h:int, buttonFunction:Function = null) 
    { 
     super(id, content); 
     _label = label;   
     _buttonWidth = w; 
     _buttonHeight = h;  
     _button = makeButton(label, w, h, buttonFunction); 
     addButtonListeners(); 
     addChild(_button); 
    } 


    protected function makeButton(label:String, w:int, h:int, buttonFunction:Function = null):Sprite { 
     _button = new Sprite(); 
     _button = drawButton(_button); 
     _button.useHandCursor = true; 
     _button.buttonMode = true; 
     _button.mouseChildren = false; 


     _button = addTextField(label, _button); 
     return _button; 
    } 

    protected function addTextField(label:String, button:Sprite):Sprite { 
     _textFormat = new TextFormat(_font, _fontSize, _fontColor, false, null, null, null, null, TextFormatAlign.CENTER); 
     _textField = new TextField(); 
     _textField.defaultTextFormat = _textFormat; 
     _textField.name = "textField_" + id; 
     _textField.text = _label; 
     _textField.selectable = false; 
     button.addChild(_textField); 

     return button; 
    } 

    protected function addButtonListeners():void { 
     _button.addEventListener(MouseEvent.CLICK, mouseClick); 
     _button.addEventListener(MouseEvent.ROLL_OVER, mouseRollover); 
     _button.addEventListener(MouseEvent.ROLL_OUT, mouseRollOut); 
    } 

    protected function mouseClick(e:MouseEvent) { 
     e.stopPropagation(); 
     if (_buttonFunction) { 
      _buttonFunction(); 
     } 
     changeButtonDisplay(); 

     trace("click"); 

    } 

    protected function mouseRollover(e:MouseEvent) { 
     changeButtonDisplay(0xFF0000); 
    } 

    protected function mouseRollOut(e:MouseEvent) { 
     changeButtonDisplay(0xFFCC00); 
    } 

    protected function changeButtonDisplay(u:uint = 0xFF0000, w:int = 110, h:int = 30):void { 
     _button = drawButton(_button, w, h, u); 
    } 


    protected function drawButton(button:Sprite, w:int = 110, h:int = 30, u:uint = 0xFFCC00):Sprite{ 
     button.graphics.beginFill(u); 
     button.graphics.lineStyle(1); 
     button.graphics.drawRoundRect(0, 0, w, h, 20); 
     button.graphics.endFill(); 
     button = addTextField(_label, button); 
     return button; 
    } 
} 

} 

Любые предложения были бы очень признательны.

+0

Вы поняли это? – BadFeelingAboutThis

+0

Все фиксированные. Спасибо за вашу помощь! :) – BlackBishop88

ответ

0

Скорее всего, ваш TextField проходит мимо остальной части вашей кнопки.

Не похоже, что вы устанавливаете границы текстового поля, поэтому это будет значение по умолчанию (обычно это квадрат 100x100).

Я предлагаю явно установить ширину и высоту текстового поля в соответствии с вашей кнопкой.

_textField.width = _buttonWidth; 
_textField.height = _buttonHeight; 

Или вместо этого, если вы не хотите весь текст видимым независимо от того, что вы могли бы использовать autoSize свойство, чтобы текстовое поле оценки соответствия фактического текста.

_textField.autoSize = TextFieldAutoSize.LEFT; 
+0

Благодарим за отзыв. Я попытался добавить ширину и высоту, как было предложено, и теперь мышь и мышечка собираются внизу экрана. По крайней мере, я знаю его проблему с текстовым полем. – BlackBishop88

+0

Также я узнал, что если я вручную вводим в 110 для textfield.width и textfield.height как 30, а не ссылку на buttonheight и width, это работает. textfield.width ожидает число не int. – BlackBishop88

+0

Вы можете присвоить 'int' свойству' Number'. – BadFeelingAboutThis

Смежные вопросы