Timer [MX]

Umm… I was planning on making a random message appear, but, when I did try it , all appear really quick and were impossible to read. Is there anyway to make a timer in actionscript, for example to make a message change every 5 seconds or so? And also, someone mentioned to me a component, and I’m not a fan of the components, so if anyone can help me out and either give me a url to creating a timer, or be helpful to write down a code :whistle: It would be greatly appreciated…:s:

here is the code:



_root.onEnterFrame = function ()
{
	newTimer = getTimer () / 1000;
	if (newTimer - oldTimer >= 5)
	{
		oldTimer = getTimer () / 1000;
		trace ("now");
	}
};

where it says trace(“now”) you would put the command for displaying the new message… the code is pretty self-explanitory…

:s: Thanx Alot man ! Well since I’m really a newbie at actionscript and I only know so much, can you explain more thoroughly what I would have to put inside the trace parenthesis, and what does trace do? If not it’s cool, and thx alot ! :wink:

well you would replace trace() with whatever you are using to display your random messages. trace just shows you the value of something, but it only does so inside of flash. once the movie is published it stops working…

:stunned: Oh cool, well now I understand where to place my code ;). Thx for the help man! Now I gotta go to work!:bounce:

no problem. post if you need anything else…

Fine if you insist :beam: I was wondering how can i make a draggable scroller, for exampled I know how to make the buttons to scroll text etc. I already know how to do that, what I was wondering how can i make the scroll-bar scroll everytime the user either clicks the button, or they drag the scroll bar to scroll the text… how would i do this? and if its in a site, please post the site’s url :wink: ok cool, hope you can help :slight_smile:

well if you know how to scroll text, then you can check this tutorial and it might help you on your way…

http://www.kirupa.com/developer/mx/slider.htm

Oh yes the powerful Kirupa Slider, I tried, and since I am a super newbie, I tried to make it scroll text… but failed miserably. Maybe you can be of some help, I’ve only used the sliders to control volume and pan when I add music to my site… but when it comes to scrolling text , it failed… help please :*(

well I’ll try (haven’t tried yet) and I’ll let you know, but I probably won’t have an answer tonight…

Ok cool man, I really appreciate all the help man. ThX Alot!:wink:

Ok, here ya go… get ready for this…

dragger.onPress = function ()
{
	this.startDrag (true, line._x, line._y, line._x, (line._height + line._y)); //drags the bar
	//this.startDrag(
	this.onEnterFrame = function ()
	{
		ratio = Math.round ((this._y - line._y) * 100 / line._height); // finds the ratio. % that the bar has moved on line
		if (Number (scrollableText.scroll) <= Number (scrollableText.maxscroll) && Number (scrollableText.scroll) > 0)
		{
			scrollableText.scroll = ratio * scrollableText.maxscroll / line._height; //scrolls the text
		}
	};
};
dragger.onRelease = dragger.onReleaseOutside = function ()
{
	this.onEnterFrame = function ()
	{
		this._y = ((scrollableText.scroll*(line._height*line._height))/(100*scrollableText.maxscroll))+line._y //moves the drag-box with the scroll of the ttextbox
	};
	stopDrag ();
};
up.onRelease = up.onReleaseOutside = down.onRelease = down.onReleaseOutside = function ()
{
	this.onEnterFrame = null; //turns off the button functions.
};
up.onPress = function ()
{
	this.onEnterFrame = function ()
	{
		currentScroll = scrollableText.scroll;
		if (Number (currentScroll) > 1)
		{
			scrollableText.scroll = currentScroll - 1; //scrolls the text up.
		}
	};
};
down.onPress = function ()
{
	this.onEnterFrame = function ()
	{
		currentScroll = scrollableText.scroll;
		if (Number (currentScroll) < Number (scrollableText.maxscroll))
		{
			scrollableText.scroll = Number (currentScroll) + 1; // scrolls the text down.
		}
	};
};
/*_root.onMouseDown = function () // this function just traces the values of the max and current scroll of the text box.
{
	trace ("max=" + scrollableText.maxscroll);
	trace ("cur=" + scrollableText.scroll);
};*/
scrollableText = "A bunch of text went here "

And I attached the file. The code inside the file is identical to this except that the variable “scrollableText” has a lot more text… oh you’ll see when you look at the file…

Im assuming that you’ll have questions so ask away and I will try to help as much as possible…

cheers,
jubs :cowboy:

happy flashing…

oh ya, I used a combination of these two kirupa.com tutorials:

text scroller: http://www.kirupa.com/developer/flash5/scrolltext.htm

sliders:
http://www.kirupa.com/developer/mx/slider.htm

someone give me a cookie!!!

:beam: GREAT! I’ve really been breaking my head to do this, but since im a super newbie at this I’ve had a hard time. Anyways man thnx alot, I’m on my way to trying out the code… and see if I can use it for my site :wink: and I’m pretty sure I’ll have some questions, so I’ll post as soon as i’m done memorizing the code… lolz thats what I do, memorize the codes, thats the only way I can learn (hehe)

yeah wrap your brain around that. The hardest part was getting the math equations right to move the dragger according to the scroll value. I will be back tomorrow so if you have any questions I’ll help then. :slight_smile:

Ok well here are some questions, see if you can answer them. One thing I notice was, if I press the down button the scrollbar did not budge… the only way it moved was to first click on the scrollbar and then press the up and down buttons, my question is why does it do that? and second, I was wondering how was it you got it to work? I’ve been trying, but been unsuccesful :frowning: OK well thx :slight_smile:

o0o before I foger, my other question was, I want a smaller text box… I tried it, but the scrollbar stop half way, so does that mean I have to make the scroll bar the same height as the text box? or is there another way, and is it too hard?

  1. to fix the first problem, change this line:

dragger.onRelease = dragger.onReleaseOutside = function ()

to


dragger.onRelease = dragger.onReleaseOutside = dragger.onMouseDown = function ()

  1. it should work with any size text box. It works for me when I change the size of the text box. Attach your file here and I can take a look at it, but it should work.