Welcome to Dream.In.Code
Click Here
Getting Help is Easy!

Join 117,155 Programmers for FREE! Ask your question and get quick answers from experts. There are 2,496 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Scrolling when Down arrow key is pressed

 
Reply to this topicStart new topic

Scrolling when Down arrow key is pressed, problem getting arrow key to be recognized and scroll dynamic text

aryehz2
post 12 May, 2008 - 12:39 PM
Post #1


New D.I.C Head

*
Joined: 12 May, 2008
Posts: 2

Hi all,

I have this code (see below) for a scrolling text box. I would like to add to it that if the user presses or holds down the down arrow key on the keyboard, (and if possible if the user scrolls with the mouse wheel) the scroll should work too. I have tried a number of ways including adding it as a listener, a variable and just a plain on function but it has not worked. No matter what I try, the player does not seem to recognize the key press. My file is over 13 mb and this is my first post so I'm not sure if I can upload it. If you need to see it, I'll email it to you.

The only thing is that it has to be compatible with AS1.

Thanks!
Aryeh


Here is my original code: see below for my latest attempt to get the key and mouse wheel working.

CODE

txt.setMask(mask)
scrollbar.onMouseDown = function() {
if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {
this.startDrag(false, scrollbarBG._x, scrollbarBG._y, scrollbarBG._x, scrollbarBG._height-this._height)
txt.onEnterFrame = scrollThumbs;
dragging = true
}
};
scrollbar.onMouseUp = function() {
stopDrag()
dragging = false
delete this.onEnterFrame;
};
function scrollThumbs() {

var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._height)/(this._parent.scrollbarBG._height-this._parent.scrollbar._height))-1)
this.Y = (funkyVar-this._y)*.2;
this._y += this.Y;
if(Math.abs(funkyVar-this._y)<1 && !dragging){
delete this.onEnterFrame
}

}



Here is my latest attempt:

CODE

txt.setMask(mask);
scrollbar.mouseWheelEnabled;


scrollbar.onMouseDown = function() {

    if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {
        this.startDrag(false,scrollbarBG._x,scrollbarBG._y,scrollbarBG._x,scrollbarBG._height-this._height);
        txt.onEnterFrame = scrollThumbs;
        dragging = true;
    }
}
    
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
    var keyCode = Key.getCode();
    if (keyCode == Key.DOWN) {
        this.txt.scroll++;
    }
    else if (keyCode == Key.UP) {
        this.txt.scroll--;
        scrolling = true;
    }
};
Key.addListener(keyListener);
    

Key.addListener(keyListener_obj);


scrollbar.onMouseUp = function() {
    stopDrag();
    dragging = false;
    delete this.onEnterFrame;
};



function scrollThumbs() {

    var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._height)/(this._parent.scrollbarBG._height-this._parent.scrollbar._height))-1);
    this.Y = (funkyVar-this._y)*.2;
    this._y += this.Y;
    if (Math.abs(funkyVar-this._y)<1 && !dragging) {
        delete this.onEnterFrame;
    }


}
User is offlineProfile CardPM

Go to the top of the page


aryehz2
post 14 May, 2008 - 09:27 AM
Post #2


New D.I.C Head

*
Joined: 12 May, 2008
Posts: 2

BUMP: Its been a few days and no replies. I'd really appreciate anyones help.
Thanks again.



QUOTE(aryehz2 @ 12 May, 2008 - 12:39 PM) *

Hi all,

I have this code (see below) for a scrolling text box. I would like to add to it that if the user presses or holds down the down arrow key on the keyboard, (and if possible if the user scrolls with the mouse wheel) the scroll should work too. I have tried a number of ways including adding it as a listener, a variable and just a plain on function but it has not worked. No matter what I try, the player does not seem to recognize the key press. My file is over 13 mb and this is my first post so I'm not sure if I can upload it. If you need to see it, I'll email it to you.

The only thing is that it has to be compatible with AS1.

Thanks!
Aryeh


Here is my original code: see below for my latest attempt to get the key and mouse wheel working.

CODE

txt.setMask(mask)
scrollbar.onMouseDown = function() {
if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {
this.startDrag(false, scrollbarBG._x, scrollbarBG._y, scrollbarBG._x, scrollbarBG._height-this._height)
txt.onEnterFrame = scrollThumbs;
dragging = true
}
};
scrollbar.onMouseUp = function() {
stopDrag()
dragging = false
delete this.onEnterFrame;
};
function scrollThumbs() {

var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._height)/(this._parent.scrollbarBG._height-this._parent.scrollbar._height))-1)
this.Y = (funkyVar-this._y)*.2;
this._y += this.Y;
if(Math.abs(funkyVar-this._y)<1 && !dragging){
delete this.onEnterFrame
}

}



Here is my latest attempt:

CODE

txt.setMask(mask);
scrollbar.mouseWheelEnabled;


scrollbar.onMouseDown = function() {

    if (this.hitTest(_root._xmouse, _root._ymouse) && txt._height>mask._height) {
        this.startDrag(false,scrollbarBG._x,scrollbarBG._y,scrollbarBG._x,scrollbarBG._height-this._height);
        txt.onEnterFrame = scrollThumbs;
        dragging = true;
    }
}
    
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
    var keyCode = Key.getCode();
    if (keyCode == Key.DOWN) {
        this.txt.scroll++;
    }
    else if (keyCode == Key.UP) {
        this.txt.scroll--;
        scrolling = true;
    }
};
Key.addListener(keyListener);
    

Key.addListener(keyListener_obj);


scrollbar.onMouseUp = function() {
    stopDrag();
    dragging = false;
    delete this.onEnterFrame;
};



function scrollThumbs() {

    var funkyVar = -this._parent.scrollbar._y*(((this._height-this._parent.scrollbar._height)/(this._parent.scrollbarBG._height-this._parent.scrollbar._height))-1);
    this.Y = (funkyVar-this._y)*.2;
    this._y += this.Y;
    if (Math.abs(funkyVar-this._y)<1 && !dragging) {
        delete this.onEnterFrame;
    }


}


User is offlineProfile CardPM

Go to the top of the page

indrajale
post 5 Jun, 2008 - 02:18 AM
Post #3


New D.I.C Head

*
Joined: 5 Jun, 2008
Posts: 4

i just use this code to bring my txt file into flash
CODE
loadVariables("message.txt", "");


but in variable the dynamic text must "message" (without quote)


in top arrow i use this code
CODE

on (press) {
    if (_root.textbox.Message.scroll>1) {
        _parent._parent.dragpress = 1;
        _parent._parent.move = -1;
    }
}
on (release) {
    _parent._parent.dragpress = 0;
    _parent._parent.move = 0;
}



and for the down arrow i use this code
CODE

on (press) {
    if (_parent._parent.textbox.Message.scroll<_parent._parent.textbox.Message.maxscroll) {
        _parent._parent.dragpress = 1;
        _parent._parent.move = 1;
    }
}
on (release) {
    _parent._parent.dragpress = 0;
    _parent._parent.move = 0;
}


i hope this will solve your problem
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/6/08 10:38AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month