all groups > flash actionscript > may 2007 >
You're in the

flash actionscript

group:

scroll text when button held down



scroll text when button held down rockfiend
5/28/2007 11:12:58 PM
flash actionscript: Hi all,

done quite a bit of looking around, and i am sure this is easy... trying to
create a button that will scroll a section of text down (and a button to go
up). i want it to scroll continuesly and slowly when the mouse button is held
down on the button. i can get it to scroll one line when clicked using this
script on the button:

down_btn.onPress = function() {
mytext.scroll += 1;
};

no luck for when the mouse is then continued to be held down on that button.
seen some rediculously complex script that i didnt understand and some simple
script that looked like it might work, but just didnt for whatever reason.
probably me not implimenting it correctly as I am still just stumbling around
when it comes to this stuff. any help much appreciated, and very helpful would
be the actual script correctly formatted and with instruction on where to put
the script.
thanks
Re: scroll text when button held down chrebel
5/28/2007 11:51:32 PM
down_btn.onPress = function()
{
this.onEnterFrame = function()
{
mytext.scroll += 1;
}
}

down_btn.onRelease = function()
{
delete this.onEnterFrame;
Re: scroll text when button held down kglad
5/28/2007 11:53:05 PM
you must create a loop when your button is pressed if you want to repeatedly
scroll your textfield:



down_btn.onPress = function() {
if(mytext.scroll<mytext.maxscroll){
mytext.scroll += 1;
scrollI=setInterval(scrollF,100,1); // use -1 for example to scroll up
}
};

down_btn.onRelease=down_btn.onReleaseOutside=function(){
clearInterval(scrollI);
}

function scrollI(dir){
if(dir>0){
if(mytext.scroll<mytext.maxscroll){
mytext.scroll += 1;
} else {
// scrolled to max
clearInterval(scrollI);
}
} else {
// scroll up
if(mytext.scroll>1){
mytext.scroll -= 1;
} else {
// scrolled to min
clearInterval(scrollI);
}
}
}
Re: scroll text when button held down rockfiend
6/9/2007 6:27:18 PM
thanks for the ideas, and finally had a chance to look at this.

so far no luck,

chrebel, tried your script and it did not do anything. no effect at all. not
sure why.

kglad, your script gives me errors, and i do not know enough about it to know
what is wrong. errors are :

**Error** Scene=Scene 1, layer=actions, frame=159:Line 5: Type mismatch in
assignment statement: found Number where Function is required.
scrollI=setInterval(scrollF,100,1); // use -1 for example to scroll up

**Error** Scene=Scene 1, layer=actions, frame=159:Line 10: Type mismatch.
clearInterval(scrollI);

**Error** Scene=Scene 1, layer=actions, frame=159:Line 19: Type mismatch.
clearInterval(scrollI);

**Error** Scene=Scene 1, layer=actions, frame=159:Line 27: Type mismatch.
clearInterval(scrollI);

Total ActionScript Errors: 4 Reported Errors: 4

thanks for any additional ideas
Re: scroll text when button held down kglad
6/9/2007 8:24:28 PM
function scrollI(dir){

should be:

function scrollF(dir){
Re: scroll text when button held down rockfiend
6/9/2007 9:52:58 PM
ahah! that has worked! excellent, thank you. had a play with making the "UP"
button with little success, however. not sure if i copy all the code a second
time and change names of variables, or just add a function for up at the
top.... a little more help and we have got it, thanks!

Re: scroll text when button held down kglad
6/9/2007 10:17:26 PM
:



up_btn.onPress = function() {
if(mytext.scroll<mytext.maxscroll){
mytext.scroll += 1;
scrollI=setInterval(scrollF,100,-1);
}
Re: scroll text when button held down rockfiend
6/10/2007 12:00:00 AM
kglad,
you've nailed it! got it working without a hitch now. had to change the += to
a -= in your last post to keep it from going down a line before going up and
had to change a <maxscroll to a <=maxscroll so that it didnt get stuck at the
bottom and not scroll up. and add in the release part of it for the up button
as well so it didnt just scroll up endlessly. somehow i managed to understand
it enough to do that, so maybe there is hope for me yet.

thanks again, wouldnt have got it without ya. attached is final complete code
for anyone else trying to do this. paste in your actions layer or whatever for
that part of your movie, make a button and name the instance "down_btn" make
another button and name the instance "up_btn" and make your text dynamic and
scrollable with instance name "mytext". done! brilliant!

down_btn.onPress = function() {
if(mytext.scroll<mytext.maxscroll){
mytext.scroll += 1;
scrollI=setInterval(scrollF,100,1); // use -1 for example to scroll up
}
};
up_btn.onPress = function() {
if(mytext.scroll<=mytext.maxscroll){
mytext.scroll -= 1;
scrollI=setInterval(scrollF,100,-1);
}
};

down_btn.onRelease=down_btn.onReleaseOutside=function(){
clearInterval(scrollI);
}
up_btn.onRelease=up_btn.onReleaseOutside=function(){
clearInterval(scrollI);
}
function scrollF(dir){
if(dir>0){
if(mytext.scroll<mytext.maxscroll){
mytext.scroll += 1;
} else {
// scrolled to max
clearInterval(scrollI);
}
} else {
// scroll up
if(mytext.scroll>1){
mytext.scroll -= 1;
} else {
// scrolled to min
clearInterval(scrollI);
}
}
}
Re: scroll text when button held down kglad
6/10/2007 3:03:14 PM
AddThis Social Bookmark Button