Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   Сдвинул все вовнутрь MC - кнопки и колесико перестали пахать (http://www.flasher.ru/forum/showthread.php?t=85495)

afarber 24.09.2006 01:36

Сдвинул все вовнутрь MC - кнопки и колесико перестали пахать
 
Вложений: 1
Привет,

был у меня простой чат из двух 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);
      }
}

Теперь почему-то работает только клавиша ENTER, а кнопки и колесико мыши
перестали. Мне кажется я не учел какую-нибудь мелочь... Кто-нибудь видит,
в чем тут у меня дело?

Спасибо
Алекс

silin 24.09.2006 20:30

а фокус-то до кнопок не доходит, когда ты проверяешь..
имхо проще/надежней хиттестом смотреть:
Код:

public function onMouseDown() {
               
                if (_root.hitTest.call(down_btn,_root._xmouse,_root._ymouse)) {
                        trace('DOWN');
                        area_txt.scroll--;
                        update_buttons();
                }
                if (_root.hitTest.call(up_btn,_root._xmouse,_root._ymouse)) {
                        trace('UP');
                        area_txt.scroll++;
                        update_buttons();
                }
        }


afarber 25.09.2006 00:47

Вложений: 1
Цитата:

Сообщение от silin
а фокус-то до кнопок не доходит, когда ты проверяешь..
имхо проще/надежней хиттестом смотреть:

А-а спасибо, я не сообразил про фокус (а до TextField доходит, странно...)

Я еще немного подумал и сделал немного по другому - с 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) все еще
не работает... Подскажите как исправить?

Спасибо
Алекс

afarber 25.09.2006 00:58

Я вот и так попробовал - с 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);
        }
}


Juice_Green 25.09.2006 11:29

попробуйте написать так, для примера:
Код:

        public function scrollUp() {
                this.area_txt.scroll--;
                updateButtons();
        }


afarber 25.09.2006 17:01

Вложений: 1
Цитата:

Сообщение от Juice_Green
this.area_txt.scroll--;

Привет, нет - this ничего не изменил - см. attachment

Мне кажется this здесь не нужен так как area_txt здесь одна, и в scope

silin 25.09.2006 22:08

ничего не понял: все крутит..
к слову: для selectable текста будет крутить и без onMouseWheel (но только когда мышь над ним)

afarber 25.09.2006 23:44

Sorry - я воткнул другую мышь в лаптоп и теперь
у меня тоже закрутило. Виноват!

Про selectable text понял, спасибо

pkfun 26.09.2006 10:07

Из Help к восьмерке:
Цитата:

The default properties of a text field are as follows:

type = "dynamic"
border = false
background = false
password = false
multiline = false
html = false
embedFonts = false
selectable = true
wordWrap = false
mouseWheelEnabled = true
condenseWhite = false
restrict = null
variable = null
maxChars = null
styleSheet = undefined
tabInded = undefined


Часовой пояс GMT +4, время: 20:43.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.