Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-23-2001, 09:51 AM   #1
Perlaki
Registered User
 
Join Date: Dec 2000
Location: Liverpool, England
Posts: 33
Arrow

How long is a piece of string? Sorry, couldn't resist it.

I need to control the length of a string.
I have a dynamic text box, that displays the velocity of my MC. Sometimes it shows up as 2.5, and sometimes 3.3423452352

Can I control it using one of the Functions>String functions. I've tried a few but am at a loss.
Please help?
Cheers
Simon
Perlaki is offline   Reply With Quote
Old 03-23-2001, 11:20 AM   #2
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

A string is twice the length from the middle to either end

Now as for your problem, take a look at this sample script:

myString = "123.456789";
decimals = 2;
dotIndex = myString.indexOf( "." ) + 1;
shortened = myString.substr( 0, dotIndex+decimals );

decimals is a variable which you set to the number of decimal places you want to show.

Note this will totally screw up if there is no decimal point.. you'll have to add an If clause if that is at all likely, which cheks if:
myString.indexOf( "." ) == -1;
and if so, aborts. This means there is no dot in the orriginal string (indexOf returns -1 if it doesn't find the search string, which is a dot in this case).

Cheers

Jesse
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder
Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 03-23-2001, 11:40 AM   #3
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

you could also use the Math.round( ); action. It will round your number down to the nearest integer. Or if you want a string of an exact length you can use
substring(string, index, count);..for example,
if myString = "onetwothree";
then writing...
newString =substring(myString, 1, 6);
would leave newString = "onetwo";
ie. six chars from the string.
I think that is for flash 4, but you can use the
myString.substring(from, to);
in flash 5.

A

mad_A is offline   Reply With Quote
Old 03-23-2001, 12:11 PM   #4
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

Like Arrays, Strings in Flash 5 are zero based so the first letter in a string is element Zero.
So if you wanted to use Mad_A's exmaple you would need to use myString.substring(0,6)

Cheers

Jesse
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder
Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 03-23-2001, 12:16 PM   #5
Perlaki
Registered User
 
Join Date: Dec 2000
Location: Liverpool, England
Posts: 33
Wink

Nice one man, now I know how long my string is, plus I can control the length of my string. That's one more problem, solved, thanks a lot Jesse.
Do you know a way of controlling G Strings? That would be handy!
Perlaki is offline   Reply With Quote
Old 03-23-2001, 12:21 PM   #6
Perlaki
Registered User
 
Join Date: Dec 2000
Location: Liverpool, England
Posts: 33
Default

I've just seen your method Mad_A, but I'd already applied Jesse's. Thanks anyway,
Simon
Perlaki is offline   Reply With Quote
Old 03-23-2001, 12:22 PM   #7
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

Lol. I'm afraid I've not had much experience with those sorts of Strings yet

Cheers

Jesse
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder
Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
new string functions! tell me what you need! colfaxrev ActionScript 2.0 11 09-23-2008 10:59 PM
Limiting variable text string length RQFlash ActionScript 2.0 1 07-06-2006 04:16 PM
Parsing mtanti ActionScript 2.0 3 02-24-2006 04:37 PM
06++ = 7 != 07 Flash Gordon Server-Side Scripting 5 01-17-2006 07:27 PM
Can't get the length of a string j1mmy Simple Stuff (Newbies) 5 10-11-2002 07:50 PM


All times are GMT. The time now is 02:30 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.