Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop dynamic text field 1

Status
Not open for further replies.

Micher

Technical User
May 18, 2001
9
CH
Hi guys!

I try to create a dynamic text field to scroll down continously (without button!) and smoothly. It also should loop without breaking.

It tried like this:
Code:
onClipEvent (enterFrame) {
    _root.Textfield.scroll += 1;
}

but that scrolls to fast and I don't know how to loop it.
Has anyone any idea how this could be done?

Thanks for your help
MICHER
 
You could try this...

onClipEvent (enterFrame) {
_root.textField.scroll++;
if(_parent.textField.scroll>=_parent.textField.maxscroll) {
_parent.textField.scroll = 1;
}
}


It's not the smoothest way to loop the text because when the text hits the bottom it jumps straight to the top rather than rolling around one line at a time.

If you do want a continuous flow you'll have to parse the text line by line using methods of the String() object, using an index variable and nested "for" loop to move through the text cutting it into chunks just big enough to fill the textbox then incrementing the index and doing the whole process repeatedly. When the index exceeds the length of your text it is reset to the beginning again.

That's potentially a lot of code and will be pretty slow as the String() object is notoriously inefficient.
 
Wang...

Pushed by your continous suggestion to use the onClipEvent action... I've been experementing on my own trying to understand all it's subtleties.

Isn't Micher's "fast scroll" problem here, caused by the fact that the scroll would be updated in every frame of the onClipEvent?

Regards,
new.gif
 
Absolutely - scroll speed in this example is governed by the frame rate of the movie, I was just suggesting a solution for the looping part.

I think the best way around this problem would be to use a variable to control the scroll speed, perhaps linked to getTimer() so that the variable is incremented every half second say and the scroll property is directly linked to this variable. Something like this added to the last idea would get you close (based on a frame rate of 12fps)...

onClipEvent(enterFrame){
count=getTimer();
if(count%6==0){
scrollControl++;
}
_root.textField.scroll=scrollControl;
}
 
I've done this... Based on a 12fps frame rate, this will update the scroll every 2 seconds (2*12=24).

Outside of being a longer script than your's (thus more typing!)... Is it as valuable & efficient?

onClipEvent (load) {
_root.count = 0;
}
onClipEvent (enterFrame) {
if (_root.count == 24) {
_root.holder.textfield.scroll += 1;
}
if (_root.count == 24) {
_root.count = 0;
}
_root.count++;
updateAfterEvent();
}

Stuck in updateAfterEvent() ... Seems to make a difference, but maybe just an illusion on my part!
When should this updateAfterEvent() be used anyway, and what does it actually do? Does it update everything contained in the event, but only when it has left the frame and before it enters the next one? As opposed to updating things, line per line, as they occur within the action?

Regards,

new.gif
 
They're both valid ways to get a result. I like using the modulus operator because it means the variable doesn't have to be reset and so removes a conditional test. Using getTimer() maintains the speed of the scroll regardless of how busy the movie gets (as framerate will drop on slower machines as soon as several events are running simultaneously). The way I implemented it wasn't too smart however now that I think about it and running a count incremented every frame is probably a better solution in this case.

updateAfterEvent() refreshes the screen and is useful for smoothing out animations - especially good in conjunction with onClipEvent(mouseMove) etc for smoothing out a dragged movieClip's motion. Because the screen is refreshed every frame anyway it's not particularly useful on (enterFrame) events - I've certainly never noticed the difference. It's best used with mouse and Key events, again on slower machines you notice the difference more.
 
Wangbar, Oldnewbie!

Thanks for your comments. However I got into trouble putting the looping part together with the count variable from wang: It jumps back to the first line, but then stops scrolling.
Additionally, I wanted to load the variable from a text file, but then the onClipEvent() didn't work anymore! Can't this be done?

Thanks again for your help!
 
Sure! Works fine from a loaded text file, over here!

Regards,
new.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top