/    Sign up×
Community /Pin to ProfileBookmark

parameterizing an array through the setTimeout(); function

Hi all,
I was just curious, I was having some trouble with the setTimeout(); function (as ussual). I am trying to send an array to a function, using this code:

setTimeout(‘animate_strip(“‘ + stripName +'”);’, 1000);

where my function is; ‘animate_strip(stripName)’, my array is ‘stripName’ (an array of element IDs for dynamically created images [in a FILM strip]).

My problem is not sending through the data, but the format it is sent as. When the animate_strip(); funciton is excuted, it seems to percieve the array of IDs as a string of IDs, which is useless to me.

here is a cutdown example of the problem:
[URL=http://www.alphalink.com.au/~ynismor/1.htm]problem[/URL]

Reprogramming the script without parameters (and instead using globals arrays) is not an option.
My only question is how the hell do I send through an ENTIRE array and NOT it’s values?
If anyone can help me with this problem I would be most grateful.
Thx

RC

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Willy_DuittSep 11.2004 — Try [i]this.onload[/i]....

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script language="javascript"&gt;
function animate_strip(stripName)
{
alert(stripName);
for(var clipNo in stripName)
{
alert('value' + clipNo + ': ' + stripName[clipNo]);
}

<i> </i> [color=red]setTimeout(this.onload, 1000);[/color]

<i> </i> }

&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="animate_strip(imgList1);"&gt;

&lt;script language="javascript"&gt;
var imgList1 = new Array("ele_ID1", "ele_ID2", "ele_ID3", "ele_ID4", "ele_ID5");
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;


.....Willy
Copy linkTweet thisAlerts:
@ReikenauthorSep 13.2004 — Wow, your right, what a tricky piece of code. That's pretty cool, I don't even know what the 'this' variable is relating to.

Although I am curious, what should I do in this instance;

[CODE]
<html>
<head>
<script language="javascript">
function animate_strip(stripName)
{
alert(stripName);
for(var clipNo in stripName)
{
alert('value' + clipNo + ': ' + stripName[clipNo]);
}

setTimeout([What now?], 1000);
}
</script>
</head>
<body>
<script language="javascript">
var imgList1 = new Array("ele_ID1", "ele_ID2", "ele_ID3", "ele_ID4", "ele_ID5");
animate_strip(imgList1);
</script>

</body>
</html>
[/CODE]


This still gets the best of me, or is there just not a way to send an array through without turning it into an expression?

RC
Copy linkTweet thisAlerts:
@Willy_DuittSep 13.2004 — In this case the keyword [i]this[/i] is referring to the window...

In JavaScript this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of. When we define our function animate_strip() in the page, its owner is the page, or rather, the window object (or global object) of Javascript....

In regards to your second example, I would remove the [i]setTimeout[/i] from the function and use [i]setInterval[/i] to fire the function...

EG:
&lt;body&gt;
&lt;script language="javascript"&gt;
var imgList1 = new Array("ele_ID1", "ele_ID2", "ele_ID3", "ele_ID4", "ele_ID5");
setInterval('animate_strip(imgList1)', 1000);
&lt;/script&gt;



Elsewise you are leaving very few options to persist the passing of [i]imgList1[/i] as an arguement...

.....Willy
Copy linkTweet thisAlerts:
@ReikenauthorSep 14.2004 — Brilliant, thx willy, setInterval(); is an excellent substitute, I just wish I had of thought of that instead of persisting with trying to get setTimeout(); to send arguments properly! Thank god there's someone that can make sense of this stuff.

I am curious though, off topic, if I were to want to execute a function called moveImgs(); that was in a frame 'named'; film_strip. how would I get to itr from the parent document? In a feeble attempt to access the function from the parent I have used:

window.film_strip.moveImgs();

And it has obviously given he an error. Got any ideas?

RC
Copy linkTweet thisAlerts:
@Willy_DuittSep 14.2004 — Generally the parent holds all of the scripts and it is the children which are accessing the functions within the parent but you can try:

document.frames['film_strip'].moveImgs();

.....Willy
Copy linkTweet thisAlerts:
@ReikenauthorSep 16.2004 — Willy, you are a genius, I owe you one. As soon as I have finished the site I'll getya a loggin password and you can have a look.

Thx for the help.

RC
Copy linkTweet thisAlerts:
@Willy_DuittSep 16.2004 — Your welcome glad I could help... ?

Cheers;

.....Willy
×

Success!

Help @Reiken spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...