Vous êtes sur la page 1sur 4

Digital Time using Actionscript in Flash

1. The Date class in Actionscript along with its various methods helps us
to retrieve date and time values (Local / GMT).
2. Create three Dynamic Textboxes for displaying the hours, minutes,
seconds and name their variables as ch, cm, cs respectively.
3. Write the following Actionscript code in the Actions window (F9) as
given below:
var dt, timeint;

dt = new Date();
ch = dt.getHours();
cm = dt.getMinutes();
cs = dt.getSeconds();
timeint=setInterval(timer,1000);

function timer() {
dt = new Date();
ch = dt.getHours();
cm = dt.getMinutes();
cs = dt.getSeconds();
}
4. Variables dt, timeint Flash are first declared using the keyword 'var'
and any function can be defined by using the keyword 'function'
followed by a function-name and the function code which can be
written within the {...} as shown above.
5. The constructor new Date() is used create an instance of the Date
object and assigned to the variable 'dt'.
6. The methods getHours, getMinutes, getSeconds of the Date object are
used to retrieve the hours, minutes, seconds and assigned to the 3
Dynamic Textbox variables.
7. Save your work and test the Movie (Ctrl + Enter). That's it you have
learnt how to create scrolling textboxes in Flash using Actionscript.
Note: GMT time can also be displayed in a similar manner by using the
getUTCHours(), getUTCMinutes(), getUTCSeconds() methods of the Date
object.
Simple Scroller for Flash Textboxes
1. In Flash, textboxes are of 3 types namely - Static, Dynamic & Input. The size
of Dynamic/Input text varies depending on the source file/user input and
hence may require the use of scrollers.
2. Create a Dynamic textbox with Multiline property selected using the
Properties panel, name the variable and the instance as 'addr' and 'scrtxt'
respectively.
3. Create 2 buttons for Upward and Downward scrolling and write the following
Actionscript code:
Upward Button
on(press)
{
scrtxt.scroll=scrtxt.scroll-1;
}

Downward Button
on(press)
{
scrtxt.scroll=scrtxt.scroll+1;
}

4. Save your work and test the Movie (Ctrl + Enter). That's it you have learnt
how to create simple scrollers for textboxes in Flash using Actionscript.

Simple Scrollbars

Advanced Scrollers for Flash Textboxes


1. Functions can be used to control the button's scrolling action to create a
more advanced type of text scrolling as explained below.
2. Write two Actionscript functions, scrup and scrdown for scrolling upwards and
downwards as shown below:
function scrup()
{
scrtxt.scroll=scrtxt.scroll-1;
}

function scrdown()
{
scrtxt.scroll=scrtxt.scroll+1;
}

3. Call these functions from the two Buttons using the following actionscript
code:
Upward Button
on(press)
{
upint=setInterval(scrup,100);
}

on(release)
{
clearInterval(upint);
}

Downward Button
on(press)
{
downint=setInterval(scrdown,100);
}

on(release)
{
clearInterval(downint);
}

4. SetInterval is used to call a function after a certain period of time until it is


cleared using the ClearInterval.
5. Thus they help in creating scrollers that can scroll until the mouse is released
as shown below.
6. Save your work and test the Movie (Ctrl + Enter). That's it you have learnt
how to create simple scrollers for textboxes in Flash using Actionscript.

Advanced Scrollbars using Mouse Press and Mouse Over Actions


Note: This is also applicable to Input text type. The rollOver and rollOut events of a Buttons can
also be used to enable scrolling during mouseover events as shown above in the second swf.

Vous aimerez peut-être aussi