-
scrolling text
i am having trouble that i hope somebody may be able to help me with. i have a text field that i can have scroll 1 line at a time, each time i click the scroll button. what i would like to do is have the text be able to continue scrolling while the button is being depressed. any help would be greatly appreciated. below is the code i already have implemented. thanks.
//-------------scroll buttons--------------\\
upButtonContact.addEventListener(MouseEvent.CLICK, scrollUp);
downButtonContact.addEventListener(MouseEvent.CLIC K, scrollDown);
function scrollUp(event:MouseEvent):void
{
textBox.scrollV --;
}
function scrollDown(event:MouseEvent):void
{
textBox.scrollV ++;
}
//-------------/scroll buttons--------------\\
-
It seems to me that you could use a loop to keep repeating the scroll up or down command untill the mouse is released.
-
i attempted to do that but i was unsuccessful. do you have any suggestions. i defined a variable to repeat 20 times, just for a test run. and instead of putting ++ or -- i tried imputing the variable a few different ways, but still no luck.
-
The logic behind it would be...
When mouse is depressed {
Declare var counter = 0
While counter <1000
scoll down or up
the length should cover for as long as it would take to scroll the text.
Alternativly...you could link the loop statement so that it loops untill the mouse is released...Im still at the point where I can think of ways to solve things...but Im not very good at using AS to implement them yet...
hopefully this helps a bit, but I do not think I can be of much more help
-
i haven't tried it yet, but thanks for all your input. im basically at the same point as you. i know what i want to do and how to go about it. but not really sure how to make it work.
-
function upscroll(e:Event)
{
e.currentTarget.scrollV ++;
}
textBox.addEventListener(Event:ENTER_FRAME, upscroll);
Do the same for the other direction.
Then add
function mouseUp(e:MouseEvent)
{
textBox.removeEventListener(Event.ENTER_FRAME, upScroll);
}
upButtonContact.addEventListener(MouseEvent.MOUSE_ UP, mouseUp);
-
is ENTER_FRAME what i would actually put in or do i put the frame number that im trying to command?
-
That is an event, which will continously let your scroll move.
-
when i run the movie with the text as is. it says there is an error in the following line:
textBox.addEventListener(Event:ENTER_FRAME, upscroll);
it says:
1084: Syntax error: expecting rightparen before colon.
-
Sorry, must be Event.ENTER_FRAME
-
so. i hope this isn't getting to be a huge pain for you. but now it kind of works. i've copied the code for each button and made the appropriate changes. now......only the down button works, and when it does, it scrolls all the way to the bottom of the text file even when you click and release right away. below is the script i'm using now. thanks for all the help so far.
function downscroll(e:Event)
{
e.currentTarget.scrollV ++;
}
textBox.addEventListener(Event.ENTER_FRAME, downscroll);
function mouseUp(e:MouseEvent)
{
textBox.removeEventListener(Event.ENTER_FRAME, downscroll);
}
upButtonContact.addEventListener(MouseEvent.MOUSE_ DOWN, mouseUp);
function upScroll(e:Event)
{
e.currentTarget.scrollV --;
}
textBox.addEventListener(Event.ENTER_FRAME, upScroll);
function mouseDown(e:MouseEvent)
{
textBox.removeEventListener(Event.ENTER_FRAME, upScroll);
}
downButtonContact.addEventListener(MouseEvent.MOUS E_DOWN, mouseDown);
-
I had only made a suggestion. The implementation is more complex:
PHP Code:
var isScroll:Boolean;
function mouseDownScroll (e:MouseEvent)
{
isScroll = true;
function downscroll (e:Event)
{
if (!isScroll)
{
e.target.removeEventListener (Event.ENTER_FRAME, downscroll);
}
e.target.scrollV++;
}
textBox.addEventListener (Event.ENTER_FRAME, downscroll);
}
function mouseUpscroll (e:MouseEvent)
{
isScroll = true;
function upScroll (e:Event)
{
if (!isScroll)
{
e.target.removeEventListener (Event.ENTER_FRAME, upScroll);
}
e.target.scrollV--;
}
textBox.addEventListener (Event.ENTER_FRAME, upScroll);
}
function mouseUpEvent (e:MouseEvent)
{
isScroll = false;
}
upButtonContact.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownScroll);
downButtonContact.addEventListener (MouseEvent.MOUSE_DOWN, mouseUpscroll);
addEventListener (MouseEvent.MOUSE_UP, mouseUpEvent);
-
thanks so much for your help. it works great. thats one of the final headaches i have left.