PDA

Просмотр полной версии : Помогите разобраться: изменение AS для символа


o-mega
08.11.2006, 10:52
Народ, срочно нужна помощь! В AS я не силен, скажу сразу...

Пытался разобраться с тем, как делать скроллы для текстового поля. Набрел в сети на вот такой вот урок _h**p://www.flashteacher.ru/tutorials/scrolling/index.shtml . Принцип описанный там, прост:
создается поле, рисуются скроллы (потом их называют up, down и scrollbar в инстанс-нейм), все это загоняется в символ (contairnerMC), который потом выставляется в сцену. Текста берется из текстовика. Довольно просто...

Только вот у меня проблема заключается в том, что мой этот созданный символ contairnerMC находится тоже в символе. Код в примере предусматривает использование onClipEvent (а ведь использовать его можно лишь в сцене) :(

Вот непосредственно код:

onClipEvent (load){
this.loadVariables("text.txt");

scrolling = 0;
frameCounter = 1;
speedFactor = 3;
numLines = 7;
origHeight = scrollbar._height;
origX = scrollbar._x;
needInit = false;

function initScrollbar(){
var totalLines = numLines + daTextBox.maxscroll - 1;
scrollbar._yscale = 100*(numLines)/totalLines;
deltaHeight = origHeight - scrollbar._height;
lineHeight = deltaHeight/(daTextBox.maxScroll - 1);
}

function updateScrollBarPos(){
scrollbar._y = lineHeight*(daTextBox.scroll - 1);
}

}

onClipEvent (enterFrame){
if( needInit ){
if(daTextBox.maxscroll > 1){
initScrollbar();
needInit = false;
}

}

if( frameCounter % speedFactor == 0){

if( scrolling == "up" && daTextBox.scroll > 1){
daTextBox.scroll--;
updateScrollBarPos();
}

else if( scrolling == "down" && daTextBox.scroll < daTextBox.maxscroll){
daTextBox.scroll++;
updateScrollBarPos();
}
frameCounter = 0;
}
frameCounter++;
}

onClipEvent (mouseDown){

if(up.hitTest(_root._xmouse,_root._ymouse)){
scrolling = "up";
frameCounter = speedFactor;
up.gotoAndStop(2);
}

if(down.hitTest(_root._xmouse,_root._ymouse)){
scrolling = "down";
frameCounter = speedFactor;
down.gotoAndStop(2);
}

if(scrollbar.hitTest(_root._xmouse,_root._ymouse)){
scrollbar.startDrag(0,origX,deltaHeight,origX);
scrolling = "scrollbar";
}

updateAfterEvent();

}

onClipEvent (mouseUp){
scrolling = 0;
up.gotoAndStop(1);
down.gotoAndStop(1);
stopDrag();
updateAfterEvent();
}

onClipEvent (mouseMove){
if(scrolling == "scrollbar"){
daTextBox.scroll = Math.round((scrollbar._y)/lineHeight + 1);
}

updateAfterEvent();

}

onClipEvent (data){
needInit = true;
}
Можно ли заменить этот onClipEvent на что-нибудь другое?! Или как сделать так, чтобы это все работало в символе и остался этот onClipEvent?! Потому как более половины переменных отказываются работать без нее...

iNils
08.11.2006, 13:57
o-mega, если вы не сильны в AS, то ваши вопросы надо задавать в разделе для начинающих. Для оформления кода используются теги , а не .

o-mega
09.11.2006, 20:08
Неужели ни у кого мыслей не возникло...

Хемуль
11.11.2006, 01:15
2 o-mega:
Есть. Использовать обработчики onMouseMove, onMouseDown и т.д.

wvxvw
11.11.2006, 05:35
var _txt:TextField = _root.createTextField("_txt", 0, 5, 5, 200, 200);
with (_txt) {
border = true;
borderColor = 0;
}
var _str:String = "Test text\rTest line\r";
for (i=0; i<5; i++) {
_str += _str+i;
}
_txt.text = _str;
// Поместить в библиотеку клип небольшого размера, присвоить идентификатор экспорта scroller
var scroller:MovieClip = _root.attachMovie("scroller", "scroller", 2, {_x:_root._txt._width+5, _y:5});
scroller.onPress = function() {
if (this.m_y == undefined) {
this.m_y = this._y;
this.n_y = _root._txt._height+_root._txt._y-this._height;
this._step = this.n_y/_root._txt.maxscroll;
}
this.a_y = this._ymouse;
this.onEnterFrame = function() {
this._y += this._ymouse-this.a_y;
if (this._y<this.m_y) {
this._y = this.m_y;
}
if (this._y>this.n_y) {
this._y = this.n_y;
}
_root._txt.scroll = this._y/this._step;
};
};
scroller.onRelease = function(){
delete this.onEnterFrame;
}
scroller.onReleaseOutside = scroller.onRelease;