PDA

View Full Version : Can't get the length of a string


j1mmy
10-10-2002, 09:10 PM
I can't seem to get the length of a string using this expression:
charLength = length (_root.newsclip);

This returns a value of 16 (the number of chars in the string literal "(_root.newsclip)"

How do I write the pathame down to the text location so that it is evaluated as a pathname and not a string literal?

newsclip is a movie clip and theres a dynamic text field in it that I need to get the length of.

Sorry if this is dopey, but somewhere along the way I seem to have lost the plot.

Thanks in advance.

tg
10-10-2002, 09:40 PM
//if newsclip is a variable
charLength=_root.newsclip.length;
//if newsclip is a textbox
charLength=_root.newsclip.text.length;
//if newsclip is a movie clip (which it sounds like from the name)
//... it cant be done... target something inside the mc.

j1mmy
10-11-2002, 10:07 AM
Thank you tg, though I'm afraid that doesn't work...:confused:

I have a mc on the main timeline called 'newsclip'.
Inside it is a dynamic text field called 'news'

The field 'news' inside the clip 'newsclip' gets populated from a text file. No problem there.

Next I want to count how many chars are in the field 'news'
Using this script, charLength stays at nothing.

loadVariables ("news.txt", "newsclip");
charLength = _root.newsclip.news.length;
totalLength = charLength*5;

Any suggestions?

tg
10-11-2002, 02:43 PM
if the code you showed is the code you are using, then my guess is that charLength is comming back either undefined or 0...
because:

here is what is happening.
1. flash goes out to get the data from the text file.
2. flash checks the length of news.
3. flash performs the calculation
4. flash finally finishes loading the text file and news is populated with the data.

you need to make sure the file has been loaded before you try to access the data from the file.

j1mmy
10-11-2002, 03:25 PM
Your guess was right, tg.
The data was obviously not loading by the time I wanted to address it. I thought it was loading because its local and was obviously getting there, just not soon enough to test it straightaway.

What I did in the end was attach a data event handler to the movieclip receiving the data, like this:

onClipEvent (data) {
_level0.nextFrame();
}

What this does, (for anyone reading this thread who might find it useful), is fire a command only when data has been received.

SO...
1. put a 'stop' on the main timeline
2. put an onClipEvent (data) on the clip receiving the variables
3. load the variables into your movieclip
4. the movie clip sends the timeline off to the next point

Phew. That took *ages* when its really simple. I suppose thats just the way these things work out.

Of course, if it was Lingo, I'd have done it in 30 seconds ;)

tg
10-11-2002, 06:50 PM
ya, but next time you wont even have to think about it.