Horizontal Scroll [AS3]

TFlan

I could change this in my User CP.
Reaction score
64
I have a dynamic textfield with a width of 100px. If the text in that field is greater than 100px, I have it "scroll" so you can see the text in the window. But the function I made, doesn't actually scroll the text, it just widens the textfield and changes its position in the x direction.

Here's what I have, it's crude, but it works.

Code:
var titleTimer:Timer = new Timer(70);
titleTimer.addEventListener(TimerEvent.TIMER, scrollTitle);
titleTimer.start();

function scrollTitle(e:Event):void {
	var format = orgSongTitle.getLineMetrics(0);
	var size = format.width;
	if(size >= 90){
		songTitle.width = size + 50;
		songTitle.x -= 1;
		songTitle.text = orgSongTitle.text;
	}else{
		songTitle.width = 100;
		songTitle.x = 0;
	}
	if(songTitle.x <= (songTitle.width * -1)){
	   songTitle.x = 0;
	}
}

I tried looking at scrollH, but whenever I have the field with text that should overflow, the maxScrollH returns as 0 when I trace it. I found that when I change the text of the textfield, if it doesn't fit initially, it will crop the extra words out and won't put them back unless you change the text again to the original text, so long as you widened the field.

There must be a better way to do what I'm trying to do...

EDIT::

Nevermind I figured it out... just changed the textfield type from multiline to singleline and scrollH worked.
Here's the function I used if anyone is interested:
Code:
var titleTimer:Timer = new Timer(70);
titleTimer.addEventListener(TimerEvent.TIMER, scrollTitle);
titleTimer.start();

var scrollPause:Number = 0;

function scrollTitle(e:Event):void {
	if(songTitle.scrollH == songTitle.maxScrollH){
		if(scrollPause == 41){
			scrollPause = 0;
		}
		if(scrollPause == 40){
			songTitle.scrollH = 0;
			scrollPause = 0;
		}else{
			scrollPause += 1;
		}
	}else{
		if(scrollPause == 41){
			songTitle.scrollH += 1;
		}else{
			scrollPause += 1;
		}
	}
}

Gives it a 2 - 3 second pause before scrolling - which is nice, I think.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top