all groups > flash (macromedia) > october 2004 >
You're in the

flash (macromedia)

group:

Array.length doesn't work? Perhaps a few problems with my script, any help would be appreciated!


Array.length doesn't work? Perhaps a few problems with my script, any help would be appreciated! ryanlucier NO[at]SPAM cogeco.ca
10/17/2004 8:30:44 PM
flash (macromedia):
What I'm trying to do is load the test.txt file into flash, and then
put each value on every line into an array.

My problem essentially is sometimes the allURLs array shows up totally
empty when I trace it, and allURLs.length NEVER works?! If anyone
could help me here I would be greatly appreciative!

test.txt file:
=======================================================
http://www.test.com
http://www.google.ca
http://www.pbnation.com
http://www.yahoo.com

My Code:
=======================================================
bigURLstring = new Array();
allURLs = new Array();

// The below code removes the extra carriage return windows adds (that
// is, /r/n, and it changes it to /r only) Also puts each URL in the
text
// file to a seperate position in the allURLs array.
// example: allURLs[1] = http://www.google.ca

urlsfromfile = new XML();
urlsfromfile.onData = function(data)
{
data = data.split("\r\n").join("\r");
bigURLstring = data;
allURLs = bigURLstring.split("\r");
};
urlsfromfile.load("test.txt");

// This Random number generator also ALWAYS reverts to 0 I believe
because I'm
// utilizing allURLs.length which is screwing it up!

rndNum = Math.ceil(Math.random() * (allURLs.length + 1)) - 1;
randomURL.text = allURLs[rndNum];

ANY help would be GREATLY appreciated!
Thank you!
Re: Array.length doesn't work? Perhaps a few problems with my script, any help would be appreciated! Der_Zählmeister
10/19/2004 10:19:57 AM
i haven't got time to look at your code in detail, but you seem
to be mixing up strings and arrays. for both strings and arrays,
using .length will return something (length of string or length
of array). you said
bigURLstring = new Array();
if you meant it to be a string, say something like
bigURLstring = "";
or better
bigURLstring : String = String("");

if you suspect allURLs.length to be the culprit, break up your
code
rndNum = Math.ceil(Math.random() * (allURLs.length + 1)) - 1;
into
var n = allURLs.length;
trace("allURLs type is actually "+typeof(allURLs));
trace("allURLs.length value is actually "+n);
rndNum = Math.ceil(Math.random() * (n + 1)) - 1;

that should give you a clue on what is really happening.

-----
The Count, Singapore
Learning Objects (e-Learning) Consultant




[quoted text, click to view]
AddThis Social Bookmark Button