Scrolling when Down arrow key is pressed

problem getting arrow key to be recognized and scroll dynamic text

Page 1 of 1

2 Replies - 7455 Views - Last Post: 05 June 2008 - 02:18 AM

#1 aryehz2   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-May 08

Scrolling when Down arrow key is pressed

Post icon  Posted 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.

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:

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;
	}


}



Is This A Good Question/Topic? 0
  • +

Replies To: Scrolling when Down arrow key is pressed

#2 aryehz2   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-May 08

Re: Scrolling when Down arrow key is pressed

Posted 14 May 2008 - 09:27 AM

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



View Postaryehz2, on 12 May, 2008 - 12:39 PM, said:

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.

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:

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;
	}


}


Was This Post Helpful? 0
  • +
  • -

#3 indrajale   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-June 08

Re: Scrolling when Down arrow key is pressed

Posted 05 June 2008 - 02:18 AM

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


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


in top arrow i use this 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
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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1