PDA

View Full Version : Timer [MX]



newbieMX
April 1st, 2003, 06:57 PM
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:

Jubba
April 1st, 2003, 07:18 PM
here is the code:




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

Jubba
April 1st, 2003, 07:19 PM
where it says trace("now") you would put the command for displaying the new message... the code is pretty self-explanitory...

newbieMX
April 1st, 2003, 07:26 PM
: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 ! ;)

Jubba
April 1st, 2003, 07:31 PM
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...

newbieMX
April 1st, 2003, 07:34 PM
:stunned: Oh cool, well now I understand where to place my code ;). Thx for the help man! Now I gotta go to work!:bounce:

Jubba
April 1st, 2003, 07:44 PM
no problem. post if you need anything else...

newbieMX
April 1st, 2003, 08:00 PM
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 ;) ok cool, hope you can help :)

Jubba
April 1st, 2003, 08:09 PM
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

newbieMX
April 1st, 2003, 08:13 PM
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 :*(

Jubba
April 1st, 2003, 08:29 PM
well I'll try (haven't tried yet) and I'll let you know, but I probably won't have an answer tonight....

newbieMX
April 1st, 2003, 08:30 PM
Ok cool man, I really appreciate all the help man. ThX Alot!;)

Jubba
April 1st, 2003, 10:14 PM
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...

Jubba
April 1st, 2003, 10:16 PM
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

Jubba
April 1st, 2003, 10:16 PM
someone give me a cookie!!!

newbieMX
April 1st, 2003, 10:22 PM
: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 ;) 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)

Jubba
April 1st, 2003, 10:40 PM
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. :)

newbieMX
April 2nd, 2003, 02:37 PM
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 :( OK well thx :)

newbieMX
April 2nd, 2003, 02:39 PM
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?

Jubba
April 2nd, 2003, 05:38 PM
1) to fix the first problem, change this line:


dragger.onRelease = dragger.onReleaseOutside = function ()


to



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



2) 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.

newbieMX
April 2nd, 2003, 07:35 PM
OK cool, mucho thanks again man really appreciate it, I'm on my way to fixing the code and changing that line, I didnt save the version of the textbox that I did, but I'll do it again, if it does work I'll let you know, if not I'll attach it here, I'll come back in a few and thx again ;)

Jubba
April 2nd, 2003, 07:48 PM
no problem. :)

newbieMX
April 3rd, 2003, 12:18 AM
Well as i promise I'll let you know if worked or not, and in this case it didn't. :sigh: Well I attached the file so you can take a look, what I was wondering was if there's anyways for the scrollbar or actionscript (not sure which) to calculate how much is written in the text box so that th scroll bar hits all the way to the bottom.. if not its cool man, let leave it like this :player: ok man good luck:s: hope you can help ;)

Jubba
April 3rd, 2003, 11:58 AM
wow. yeah i guess that script gets messed up when you go that small... i'll keep working on it but I'm going to be really busy for the next couple days.. i'll let you know what I come up with...

newbieMX
April 3rd, 2003, 04:04 PM
ok no prob man, and still I'm really appreciated for all the help man. Well, I'll be checking if you posted or not.. ;)

Bonna
February 5th, 2004, 11:41 AM
here is a cookie