![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
|
Регистрация: May 2006
Адрес: Germany
Сообщений: 74
|
Привет,
был у меня простой чат из двух TextField-ов (для ввода и показа сообщений) и двух кнопок для scrolling-a. Все работало, включая колесико на мышке - до тех пор пока я не решил засунуть оба TextField-а и кнопки в один MovieClip в стиле AS 2.0: class Chat extends MovieClip {
private var field_txt:TextField;
private var area_txt:TextField;
private var up_btn:Button;
private var down_btn:Button;
public function Chat() {
this['mouseWheelEnabled'] = false;
Key.addListener(this);
Mouse.addListener(this);
update_buttons();
}
public function onKeyDown() {
if (Key.getCode() == Key.ENTER &&
field_txt.text != '' &&
Selection.getFocus() == targetPath(field_txt)) {
setText(getText());
Selection.setFocus(field_txt);
}
}
public function onMouseDown() {
if (Selection.getFocus() == targetPath(down_btn)) {
area_txt.scroll--;
update_buttons();
} else if (Selection.getFocus() == targetPath(up_btn)) {
area_txt.scroll++;
update_buttons();
}
}
public function onMouseWheel(lines:Number) {
area_txt.scroll -= lines;
update_buttons();
}
public function getText():String {
var str:String = field_txt.text;
field_txt.text = '';
return str;
}
public function setText(str:String) {
area_txt.scroll = area_txt.maxscroll;
area_txt.text += newline + str;
}
private function update_buttons():Void {
up_btn._visible = (area_txt.scroll > 1 ? true : false);
down_btn._visible = (area_txt.scroll < area_txt.maxscroll ? true : false);
}
}
перестали. Мне кажется я не учел какую-нибудь мелочь... Кто-нибудь видит, в чем тут у меня дело? Спасибо Алекс |
|
|||||
|
а фокус-то до кнопок не доходит, когда ты проверяешь..
имхо проще/надежней хиттестом смотреть: |
|
|||||
|
Регистрация: May 2006
Адрес: Germany
Сообщений: 74
|
Цитата:
Я еще немного подумал и сделал немного по другому - с onRelease и Delegate: import mx.utils.Delegate;
class Chat extends MovieClip {
private var field_txt:TextField;
private var area_txt:TextField;
private var up_btn:Button;
private var down_btn:Button;
public function Chat() {
field_txt.maxChars = 1024;
// will implement wheel scrolling myself
this['mouseWheelEnabled'] = false;
Key.addListener(this);
Mouse.addListener(this);
up_btn.onRelease = Delegate.create(this, scrollUp);
down_btn.onRelease = Delegate.create(this, scrollDown);
updateButtons();
}
public function onKeyDown() {
if (Key.getCode() == Key.ENTER &&
field_txt.text != '' &&
Selection.getFocus() == targetPath(field_txt)) {
setText(getText());
Selection.setFocus(field_txt);
}
}
public function scrollUp() {
area_txt.scroll--;
updateButtons();
}
public function scrollDown() {
area_txt.scroll++;
updateButtons();
}
public function onMouseWheel(lines:Number) {
area_txt.scroll -= lines;
updateButtons();
}
public function getText():String {
var str:String = field_txt.text;
field_txt.text = '';
return str;
}
public function setText(str:String) {
area_txt.scroll = area_txt.maxscroll;
area_txt.text += newline + str;
updateButtons();
}
private function updateButtons():Void {
up_btn._visible = (area_txt.scroll > 1 ? true : false);
down_btn._visible = (area_txt.scroll < area_txt.maxscroll ? true : false);
}
}
а вот мышкино колесико (onMouseWheel) все еще не работает... Подскажите как исправить? Спасибо Алекс |
|
|||||
|
Регистрация: May 2006
Адрес: Germany
Сообщений: 74
|
Я вот и так попробовал - с area_txt.onMouseWheel = Delegate(...),
но все равно не горит волшебный фонарь, не крутит колесико import mx.utils.Delegate;
class Chat extends MovieClip {
private var field_txt:TextField;
private var area_txt:TextField;
private var up_btn:Button;
private var down_btn:Button;
public function Chat() {
field_txt.maxChars = 1024;
area_txt.mouseWheelEnabled = false;
Key.addListener(this);
//Mouse.addListener(this);
up_btn.onRelease = Delegate.create(this, scrollUp);
down_btn.onRelease = Delegate.create(this, scrollDown);
area_txt.onMouseWheel = Delegate.create(this, scrollLines);
updateButtons();
}
public function onKeyDown() {
if (Key.getCode() == Key.ENTER &&
field_txt.text != '' &&
Selection.getFocus() == targetPath(field_txt)) {
setText(getText());
Selection.setFocus(field_txt);
}
}
public function scrollUp() {
area_txt.scroll--;
updateButtons();
}
public function scrollDown() {
area_txt.scroll++;
updateButtons();
}
public function scrollLines(lines:Number) {
area_txt.scroll -= lines;
updateButtons();
}
public function getText():String {
var str:String = field_txt.text;
field_txt.text = '';
return str;
}
public function setText(str:String) {
area_txt.scroll = area_txt.maxscroll;
area_txt.text += newline + str;
updateButtons();
}
private function updateButtons():Void {
up_btn._visible = (area_txt.scroll > 1 ? true : false);
down_btn._visible = (area_txt.scroll < area_txt.maxscroll ? true : false);
}
}
|
|
|||||
|
попробуйте написать так, для примера:
|
|
|||||
|
Регистрация: May 2006
Адрес: Germany
Сообщений: 74
|
Цитата:
Мне кажется this здесь не нужен так как area_txt здесь одна, и в scope |
|
|||||
|
Регистрация: May 2006
Адрес: Germany
Сообщений: 74
|
Sorry - я воткнул другую мышь в лаптоп и теперь
у меня тоже закрутило. Виноват! Про selectable text понял, спасибо |
|
|||||
|
Регистрация: Feb 2006
Сообщений: 580
|
Из Help к восьмерке:
Цитата:
|
![]() |
![]() |
Часовой пояс GMT +4, время: 08:56. |
|
|
« Предыдущая тема | Следующая тема » |
|
|