View Full Version : Question about delay (again)
AKM74
May 22nd, 2004, 06:17 PM
Hello guys. My first post on this forum. First, sorry for my English.
I search forum for tutorials on how to do this type of delay, find some very informative posts, but… I’m not a scripter, and still have no luck to integrate this “setinterval” in my script.
Here is how my script looks.
---------------------------------------------------------------------------------
btn_xpos = 40;
btn_ypos = 40;
growth = 0;
function place_btns() {
duplicateMovieClip("btn", "btn"+growth, growth);
this["btn"+growth]._x = btn_xpos;
this["btn"+growth]._y = btn_ypos;
this["btn"+growth].onRollOver = function() {
trace(this._name);
};
btn_xpos += 70;
if (btn_xpos>=200) {
btn_ypos += 48;
btn_xpos = 40;
}
}
for (i=1; i<=20; i++) {
growth++;
place_btns();
}
--------------------------------------------------------------------------
What I need is to use some kind of delay. In this script , I duplicate buttons 20 times. It work fine, but they all appear instantly. What I need, is some kind of delay between appearances of each button. Like 1-2 seconds.
If some one can help, and post this script with integrated “setinterval” in correct place, I will appreciate it.
Thanks in advance.
claudio
May 22nd, 2004, 10:03 PM
You can use an onEnterFrame handler instead of the for loop:
Instead of:
for (i=1; i<=20; i++) {
growth++;
place_btns();
}
use:
this.onEnterFrame = function() {
if (++i>20) {
delete this.onEnterFrame;
} else {
growth++;
place_btns();
}
};
or
use setInterval:
function place_btns() {
if (++i>20) {
clearInterval(id);
} else {
++growth;
duplicateMovieClip("btn", "btn"+growth, growth);
this["btn"+growth]._x = btn_xpos;
this["btn"+growth]._y = btn_ypos;
this["btn"+growth].onRollOver = function() {
trace(this._name);
};
btn_xpos += 70;
if (btn_xpos>=200) {
btn_ypos += 48;
btn_xpos = 40;
}
}
}
id = setInterval(this, "place_btns", 1000);//call the function every 1 second
AKM74
May 22nd, 2004, 11:45 PM
Thanks for your help. The first solution work only if I change
if (++i>20) {
on
if (++i<20) {
But I didn’t find way to change delay time. By default, delay not really noticeable.
Second choice (setinterval) didn’t work for me at all. For some reason first 7 buttons still appear instantly, and rest of them appears with 1 sec delay.
i'm try doing it this way...
for (i=1; i<=20; i++) {
growth++;
interv = setInterval (place_btns, 1000);
}
but no luck eather..
Voetsjoeba
May 23rd, 2004, 04:54 AM
Claudio's code does work, I just tested it.
btn_xpos = 40;
btn_ypos = 40;
growth = 0;
amount = 20;
function place_btns() {
if (growth>amount) {
clearInterval(theInterval);
} else {
duplicateMovieClip("btn", "btn"+ ++growth, growth);
this["btn"+growth]._x = btn_xpos;
this["btn"+growth]._y = btn_ypos;
this["btn"+growth].onRollOver = function() {
trace(this._name);
};
btn_xpos += 70;
if (btn_xpos>=200) {
btn_ypos += 48;
btn_xpos = 40;
}
}
}
theInterval = setInterval(this, "place_btns", 200);
AKM74
May 23rd, 2004, 11:39 AM
I guess I’m stupid, but it didn’t work for me. They appear like they suppose to, in 200ms delay, but when next one appear, previous disappear…
This is a fla file. This is a test file, so it very straightforward, only above action script.
Voetsjoeba
May 23rd, 2004, 12:30 PM
duplicateMovieClip("btn_mc", "btn_mc"+ ++growth, growth);
:sigh:
AKM74
May 23rd, 2004, 12:53 PM
Thanks many times, guys. Everything works perfect now.
Thanks again.
claudio
May 23rd, 2004, 01:16 PM
welcome ;)
Voetsjoeba
May 23rd, 2004, 01:29 PM
ditto ;)
AKM74
May 23rd, 2004, 02:41 PM
Sorry to bother you guys, but just 1 more question.
Since all this buttons (well, actually movieclips with “onreliase” function) generate dynamically, they all have instance name like “bt1”, “bt2” and so on…
After they all will be created, I will assign function to each of them, like this for example:
_root.bt1.onreliase=function() {
_root.containerMC.loadPic(0);
}
In example above, it call picture name from xml file, in my current case I will call it by picture name. But I guess it make no different. I will handle this part myself (I hope). i will add entrys in xml file and new pictures will be under indexes from 20 to 40 for example.
Ok, straight to the point.
I can duplicate function above 20 times for 20 buttons, and only change bt1 to bt* and so on, I will also change loadPic(0) to loadPic(1) ….
But at the end I will have like 40 stroke of code, and if I will have 100 buttons in the future, this number will be bigger.
Can it be done some other way? I mean to assign function with “onreliase” in runtime? (When buttons actually created). I don’t know if it makes any cense to you, English not my strong point. But still…
For example I use this code to populate buttons with thumbnails images after all buttons created.
for (var i = 1; i<=12; i++) {
loadMovie("thmb/pic_"+i+".jpg", "_root.btn_mc"+i+".btn_tb");
}
And it’s great, because no matter how many buttons I have, it always load right image in right movie. Can something similar be made for links on dynamic created buttons/movies?
Voetsjoeba
May 23rd, 2004, 03:16 PM
You already have the amount variable there, so if you use it in your script, you can change it later on and it'll automatically duplicate as many as necessary because you changed that variable.
As for the onRelease bit, here's how to do it:
//start position-----------------------
btn_xpos = 40;
btn_ypos = 40;
growth = 0;
amount = 20;
//function for duplicate---------------
function place_btns() {
if (growth>amount) {
clearInterval(theInterval);
} else {
duplicateMovieClip("btn_mc", "btn_mc"+ ++growth, growth);
this["btn_mc"+growth].id = growth;
this["btn_mc"+growth]._x = btn_xpos;
this["btn_mc"+growth]._y = btn_ypos;
this["btn_mc"+growth].onRollOver = function() {
this.blic_mc.play();
};
this["btn_mc"+growth].onRelease= function() {
_root.containerMC.loadPic(this.id);
};
btn_xpos += 72;
if (btn_xpos>=200) {
btn_ypos += 48;
btn_xpos = 40;
}
}
}
theInterval = setInterval(this, "place_btns", 200);
:)
AKM74
May 23rd, 2004, 03:32 PM
Thanx a lot. ‘m apresiate your help. I really do.
Can you explain in more detail what (this.id); mean ? I just try to undastand how it all work, instead or just blind “copy and paste”.
PS
got it. You also add this line in code "this["btn_mc"+growth].id = growth;"
did't notice it before.
Voetsjoeba
May 23rd, 2004, 03:59 PM
Yup, that stores the current number as a property, and inside the onRelease handler you use it :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.