Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : timer and action


_gary_
8/25/2006 2:29:21 PM
Currently I have the first set of AS below that closes a window by clicking on
a button. I would like to close the window automatically after 5 seconds have
elapsed from the time the window is opened, the Last set of AS that is below is
used to open the window. The middle set of AS is from a tutorial. I am needing
help putting this all together.

What i would like to happen is when the window is opened

contact_btn.onPress = function(){
contactLoader.load("contact.swf");
}

after 5 seconds the window closes using the tween close from the middle
section below

Thanks So Much for Helping in Advance


close_btn.onPress = function(){
new mx.transitions.Tween(_root.firstLoader.content.con tactLoader.content,
"_alpha", mx.transitions.easing.Regular.easeOut,
_root.firstLoader.content.contactLoader.content._a lpha, 0, 20);

var interval:Number = 5;
function someCodeToRun() {
clearInterval(mySetInterval);
trace(interval+" seconds have elapsed");
}
mySetInterval = setInterval(this, "someCodeToRun", interval*1000);

contact_btn.onPress = function(){
contactLoader.load("contact.swf");
}

blemmo
8/25/2006 3:24:25 PM
Just put the code that starts the interval inside the onRelease function too:

contact_btn.onPress = function(){
contactLoader.load("contact.swf");
mySetInterval = setInterval(this._parent, "someCodeToRun", interval*1000); //
'this' inside onPress refers to the button
}

This starts the countdown as soon as the button is pressed, so the time it
takes to load the MC will be a part of the 5 second interval. I don't know what
'contactLoader' is, if it is a MovieClipLoader, you could also start the
interval inside the onLoadInit event, that way the 5 seconds will start after
the clip was loaded.

The event of the close button can be called from the interval function:

function someCodeToRun() {
clearInterval(mySetInterval);
trace(interval+" seconds have elapsed");
close_btn.onPress();
}

hth,
blemmo
_gary_
8/25/2006 3:48:23 PM
i am doing something wrong when I insert the "SomeCodeToRun"

how exactly should this line appear in the statement

new mx.transitions.Tween(_root.firstLoader.content.con tactLoader.content,
"_alpha", mx.transitions.easing.Regular.easeOut,
_root.firstLoader.content.contactLoader.content._a lpha, 0, 20);

thanks blemmo
blemmo
8/25/2006 7:21:01 PM
_gary_
8/26/2006 4:08:04 AM
i came up with this

var interval:Number = 5;
function someCodeToRun() {
clearInterval(mySetInterval);
new mx.transitions.Tween(_root.firstLoader.content.contactLoader.content,
"_alpha", mx.transitions.easing.Regular.easeOut,
_root.firstLoader.content.contactLoader.content._alpha, 0, 20);
trace(interval+" seconds have elapsed");
}

contact_btn.onPress = function(){
contactLoader.load("contact.swf");
mySetInterval = setInterval(this._parent, "someCodeToRun", interval*1000);
}

and it works great

but it interferes with this

var interval2:Number = 1;
function someCodeToRun2() {
clearInterval(mySetInterval2);
trace(interval+" seconds have elapsed");
imageLoader.load("port_bb_01.swf");
nailLoader.load("nail_bb_01.swf");
}

ben_btn.onPress = function(){
new mx.transitions.Tween(imageLoader.content, "_alpha",
mx.transitions.easing.Regular.easeOut, imageLoader.content._alpha, 0, 20);
new mx.transitions.Tween(nailLoader.content, "_alpha",
mx.transitions.easing.Regular.easeOut, nailLoader.content._alpha, 0, 20);
mySetInterval2 = setInterval(this._parent, "someCodeToRun2", interval*670);
}

How do I differentiate them. The time delay? The Variable Number?

They both exist as AScript on the first frame of the top layer, along with
other code as well.
AddThis Social Bookmark Button