Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Flash




Extracting Number At The Exnd Of A String



I need to extract a number from the end of a button instance name. The names are like so:
b1, b2, b3...b100

How can I extract the info after the "b" when they are all different lengths?

Thanks




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Extracting Number From String
Ok I have created a bunch of buttons dynamically and I want to extract the number at the end of the instance name. I have done this before but all the names in the array were the same length with a number at the end.
This time all the instance names are different lengths but they all have at the end of them _mc0,_mc1,_mc2 etc.
I need to get that number so I can call a picture to load from another array called picMax.

Code:
btn.onRelease = function() {
_root.select = _root.picMax[Number((this._name).substring(bla))];
};

btn is a variable with the path to all the dynamic clips.
The problem with this is I don't know what bla would be in the substring().

I need a way to extract the number at the end of the instance.

Example of instance names

Code:
Adele_mc0
Adriana_mc1
Antonina_mc2
Agnes_mc3
Etc

Extracting A Number From A Movieclip Name?
hi chaps

I have a series of movieclips which on the stage are referred to as movieclip1, movieclip2.....movieclip23... etc

Now my question is, how can I get at that number using actionScript?

if i do:

this._name.length

that gives me the length of the name (number of characters)
then I think i need to do some form of count and extract the digits that are in excess of 9 (9 being number of characters in the word movieClip)

But i'm a bit confused as to how to do this....

any suggestions most greatfully appreciated.

Cheers

Extracting From A String
I need to extract the end of one string and add on a new end name.that will help me call then names mc.

Code:
function menuLauncher(mc) {
//mc will be something like eg. _level0.about_btn or _level0.home_btn
// so I need to remove the "_btn" and repleace it with "_menu"
// but this should function as a path to a movieclip called eg.
// about_menu or home_menu ect.
var mc, path;
path = mc+"_menu";
path.gotoAndPlay(1);

}
How can I do this please help. Thanks

Extracting Variables From A String
I searched for this method, but I'm not sure what keywords to use. I realize this is probably a simple question, but I don't know where to start.

If I had a variable

RGB = 223,134,52;

and from this I wanted to create the numeric variable values

R = 222;
G = 134;
B = 52;

Can anyone tell me a simple way to extract these numbers from the original string?

Thank you in advance

Extracting Parts Of A String
Does anyone know how to extract part of a string?

I am building a baby search engine in flash... so I have an array of words. what I want to be able to do is view the first letter of the string entered by a user in a text field then compare each letter in turn with the letters of the strings in the array.

i.e. word typed = john
so get first letter J and compare this with the first letter of each string in the array... then do the same for the second letter.

I know how to do efverything apart from ask for the first, or second etc letter of each string...

anyone know?

cheers

Craig

Extracting A Character From A String
The code below it what I have to control the click action for all of my thumbnails. What I'm trying to do is get information out of the click to use for loading a corresponding jpeg.


ActionScript Code:
function btnClicked(evt:Event):void{
    var thumb = evt.target;
    var thumbString = thumb.toString;
    var imageToLoad = thumb+".jpg";
    trace(imageToLoad);
    trace(thumbString);
        trace(thumb.charAt(14));
    thumb.gotoAndStop("clicked");
    // image to load info would go here.
}

trace imageToLoad gives - [object thumb6_3].jpg
trace thumbString gives - function Function() {}
trace thumb.charAt gives - TypeError: Error #1006: charAt is not a function.
at main_fla::MainTimeline/btnClicked()
on the first one I thought if I could get the number 6 out to put in a variable and then add .jpg after I could use that to load 6.jpg, 7.jpg and so on. But trying to get a character isn't working cause I figure I'm doing this the wrong way. Any suggestions?

Extracting Portions Of A String?
Hey all,

I've got string values in the format "+1000", "-07000", "+0630" etc. and I would like to extract certain parts of the string that I could then convert to numbers and perform mathematical functions on them.
i.e. pulling out the "+" or "-", "06" or "30" etc.

Can someone point me in the direction to look for this? (In ColdFusion, I would just use a mid("string", begin, end) type of function)

TIA!

Help Extracting Text From A String...
I'm trying to extract specific text that is encapsulated by certain characters.

For example if I have a string that reads:

I don't want this text>This is the text I want<I don't want this text either.

Can I use a method of the string class to extract the text between the ><

Looking at the help file for substring method, it says I need to enter a number to identify the starting and ending indices. Can I somehow use characters instead of numbers?

Thanks in advance,

iBrent

Extracting Just Numbers From A String... Help (should Be Simple?)
Hi - I'm stumped here. I'm trying to extract just numbers from a string. Namely, I'm tracing "this" which returns a path : "level0.instance1.subContainer0.subButton0" What I want to do is extract just the numbers so that I get a value of "0100" (or better yet, "100"). I've looked into substr() but it's only numbers in a sequence. Is there any way to do this???

thnx
t

Help Can't Convert String To Number With Number()
I'm pulling variables from an XML file and need to convert the strings from the XML to numbers. So, I have the following actionscript:


Code:
thisPC_Price = aPrice[0].stringValue();
trace(thisPC_Price);
trace(Number(thisPC_Price));
The first trace returns 100, which is the contents of the string (it's also treated like a string by the AS and if I try and do anything to it it will return NaN, as it should). The 2nd trace action returns NaN ..... and I have no idea why.

Anyone have any ideas?

How Can I Put A Number And A String Together So It Ends Up Being A String ?
How can I put a number and a string together so it ends up being a string ?


This doesn't work:
----------------------

somenumber=1;
somestring="File";

combination=somestring + somenumber;

----------------------

At the end i want to have this:

combination="File1";

Can anyone help ?

Pattern Matching Text In A String And Extracting Text?
hi guys

I've got a variable that holds a string eg

var banana:String = "<intro>this is an intro</intro> and this is a load of other non important information";

What i want to do is be able to extract <intro>this is an intro</intro> and place that text into a new variable.

Is this possible? - If so, could you please show me how?

Many thanks :-)

[F8] Number + Number = String?
Hi, I wonder if anyone can help me with this.
This code gives me the result 100100.


PHP Code:



var one:Number = 100;
var two:Number = 100;
var result:Number = one + two;




result then prints as 100100.
I don't understand why.

How Can I Add A Number To A String? Like As In 2+1=3 Not As In 2+1=21
How can I add a Number to a string? Like as in 2+1=3 not as in 2+1=21

I am making it so that after someone crosses a frame each time it adds a number and when it gets to 8 it does some other action. Would it be something like this? 'tracksplayed= +1;' Thanx in advance.

String To Number
I have a string which is "7". But i need it to be the number 7.
What shall i do?
Thanks in advance!
bye

String To Number
I have a string which is "7". But i need it to be the number 7.
What shall i do?
Thanks in advance!
bye

String To Number
How do I convert a string variable to a number variable?

String To Number Bug?
Hi,
I have the following code:

a="013";
b=Number(a);//returns 11

Is there a way that the string a can be converted to the right '13'?

greetings
Patrick

Number Or String
I am passing variables into flash through the param and embed tags (which use asp to get them from the URL query string)

When i pass in a variable named hole1=6, the 6 doesnt seem to be a number value. it acts like a string because when i perform functions on it (like + or -) this is the result:

6+5 = 65 instead of 6+5 = 11

any thoughts?

From String To Number
hi everyone:

from visual basic i send my swf a number formated like this, "100,000,00.56".
i use a dynamic text to show it, and i works fine.

the problem is that i need that number for another code (a graph), and it doesn't work because, i think, flash is taking it as a string, with the "," and ".".

so what i need is to format the string "100,000,00.56" into the corresponding number. and i need to do that in flash not visual basic.

help please.

thanks, take care.

Number To String?
Hi,

I have a number im trying to covert to a string so it can be displayed in a text field.

Can any one tell me how?

I have tryed.

holder = holder.toString();

but still get the same problem.

String To A Number
Hi All

So it looks as though my threshold idea is impossible. I have another idea though. Only one thing is holding me back. I need to convert a hex string to a number variable. I looked at parseInt but this appears to be a method of gaining a decimal number ie 0x44D391 would become 68208152 (I think). I need the variable to retain its original 0x.... so I can use it in the threshold method.

Cheers

Jim

String To Number
i am loading in a number from a text file. In the code below how can I change MyPercent to a Numberr variable so I can add it to other numbers?



// create a loadVars object to get the txt data
var myLoadVars:LoadVars = new LoadVars();

// wait for download of imageInfo.txt file
myLoadVars.onLoad = function(){
loadFactor();
}

function loadFactor(){
myPercent.text = myLoadVars.myFactor;
}

myLoadVars.load("factor/factor.txt");


thanks,

Urig

String To Number
How's about it?

String To Number
hi every1,

Ive been struggling with this for a while now, and I'm sure that this is pretty simple thing to do but I just cant reach it :P

How do I convert a String to number?
code:

Code:
var n:String = "123";
var t:Number = n;

trace(n); //1067: Implicit coercion of a value of type String to an unrelated type Number.


THKX

::edit:: pretty dumb example (duh) :P

The Value Of A String Number
I've used ActionScript for five years. Suddenly, I can't figure out how to derive the value of a numerical string expression.

How do I make "3" into 3???

I can't take this...

Any help would be immensely appreciated.

- Paul

XML String To Number
Hi,

I read an XML file containing numbers. Then I want to do mathamatical calculations on these however I can't seem to convert them to numbers all I get is NaN. here is my code


ActionScript Code:
function loadOldValue(TheNum) {
    trace(TheNum);
    var Yposition= new Number(TheNum);
    trace(Yposition );
}
This outputs fine for the first trace but NaN for the 2nd trace which prevents me from doing any calculations.

Thanks for any help.

String To Number...
Code:
on (release) {
var LV:LoadVars = new LoadVars();
LV.load(_root.spyderbaby);
LV.onLoad = function() {
U();
};
function U() {
LV.rating = Number;
slipknot = LV.rating;
song = _root.spyderbaby;
final = 1;
trace(star=slipknot+final);
trace(rating=star/2);
loadVariablesNum("shout.php", 0, "POST");
_parent.gotoAndStop(3);
}
}
Here is the thing, slipknot is equal to 3.
When flash executes trace(star=slipknot+final);
it outputs 31
Instead of adding 3 +1 to make 4, it puts together 3 +1 to make 31...
Then it divides 31....
Is there a fix for this?
Any help is appriciated.
Thanks for your time
~Gabor

String To Number?...
This is really easy I think, but I just couldn't find out how to do it...

How do I get a string converted into a number?

So, if I had "2" and "5", for example, I'd want them to add together to be 7, not "25"...

I dunno if this information is necessary, but I have a long string of numbers separated by commas. I'm using split(",") to put them into an array. Then, I want to add, say, array[0] + array[5]...

Thanks...

String To Number
trying to compare values but value is seen as a string so it wont add.

i.e.

var x = value from XML file. such as 1111
var y = x + 5

output is 11115
should be 1116

String To Number
Hi, does anybody know how to convert contents of a string to numbers?
I've made 2 dynamic textbox with contents that vary, as long as it's number (i use the 'restrict' method on the input), depends on the input from the user.
the problem is i want to compare the contents of the 2 box.
generally it works fine, but when it compares 2 digit number with 3 digits number, all is lost. for example, i want to compare 72 with 108, the result is 72 is greater than 108.
i tried to debug the movie, watching the variables, and it turns out that flash read the content not as 72 and 108, but as "72" and "108" (which is a string), so i'd have to convert them to number first before i can compare them, right?
the question is how? i've browsed the help topics, and the clostest i cand find is number.toString, but not the other way around.
anybody can help me?
thanks in advance

XML : I Want A Number, Not A String
Ok,

I'm loading data from an xml file.
Anything loaded from it is a string.

Later, I want to be able to do some maths, say:

aBetterNumber = xmlLoadedVar + aNumber;

aBetterNumber just turns out to be the two variables concatinated together.

Any thoughts?

String To Number
How do I convert a string (e.g. "100") to a number or boolean?

I know this is probably quite basic, but it escapes me at the moment.

Thanks
Alfred

XML : I Want A Number, Not A String
Ok,

I'm loading data from an xml file.
Anything loaded from it is a string.

Later, I want to be able to do some maths, say:

aBetterNumber = xmlLoadedVar + aNumber;

aBetterNumber just turns out to be the two variables concatinated together.

Any thoughts?

String Into Number From .txt
Hello,

I've the following problem with getting values from a .txt file into flash.The problem isn't to get the Vars into the flash but to convert a string into a number. For example: the .txt file looks like this:

&t1=200&t2=400

now i want to add both numbers out of the file. I get the values into my textfields,but then Flash don't know how to add these "strings".
Flash code looks like this:

onClipEvent (enterFrame) {
    loadVariablesNum("test.txt", 0);
    sum = _root.t1 + _root.t2
}

Is it possible to add the numbers? Or is it only possible to do this with javascript
instead the txt file?

Thanks for any comment!

Number -> String
I know there is parseInt() for String -> Number, but how do I convert the other way around?

Cheers,
Lister

I Get A String Instead Of A Number...
I have a movie clip that makes a hittest to another movie clip, and when it does that, the meaning is that it has to sum up 3 to a global variable. But instead it gives me 33. That is, it makes a String. This is my code:

I initialise the variable in the following way:

_global.gold=3;


PHP Code:



onClipEvent(enterFrame){ 
    if(this.hitTest(_parent.mc2)){             
            if(_root.vitamin >=1 and energi ==1){ 
                    energi=0; 
                _root.gold += 3;//this give me 33 ..!
             } 
          } 
}//enterFrame 




What is the problem - and what is the solution? Thank you very much.

String To Number
Hi,
when I load a var from a text file my movie read a number for string
...
I load the var1=200 but my movie read var1="200"
how I can convert this ?????

please help..

String Instead Of Number
Last edited by Anik : 2007-11-28 at 09:07.
























This has got to be simpler than I think it is.

I've got this AS:


ActionScript Code:
getURL("javascript:Resize('main',1040);");


And I want to replace the "1040" number with this...


ActionScript Code:
this.bkgnd._height - 184 + home01._height


Here's what I have now... but it's not working.

ActionScript Code:
getURL("javascript:Resize('main', this.bkgnd._height - 184 + home01._height);");



Any help?
Thanks!

Number Or String => String
Hello people,

I have a function wich gets a number, this could be like 12.5(=number) or like "12.4"(=string).
I want the variable always to be a string;

function to_string(a_getal) {
// This is where the code should be
// if (a_number = [a number]) {
// a_number = string(a_number)
// }
trace(a_number.length); // This won't work if it's a number
trace(a_number);
}
to_string(12.4);
to_string("12.4");


Please, help!

Mzzl, Chris

Converting A String To A Hex Number...
I am currently storing a serious of details as hex numbers and then converting them back to strings to work with them as scores.

Once I have checked against the 'highest' score I need to update these strings back into hex.

How can I detect they are above 9 and convet to appropriate hex values... Is there a reverse of the ParseInt command I can use ??? Helpme please - confused maths dropout!!!

burt

Getting Line Number Of A String
Heya people!

The Problem:
I have a string variable (some text in it).

Say it is like this:

>< Abc abd
>< dfg fgd
>< lka lak

The >< present some kind of markers.

How can i find out on which LINE (Scroll line) in TEXT field those markers are once i put that variable into TextField.

Changing String To Number
Hi,

I need to change string to number but the problem is that string is a hex rgb value (0xAAFF13).
If you declare a var with 0xAAFF13 its value is something like 16777215.
I use it for RGB change. Available colors are stored in Array. I used "" for storing values in array because Actionscript gets confused if I try to push 0xAAFF13 without "".
Using Number returns NaN.

Any suggestions?

Thanks
Igor

String To Number From TXT File
Ok, i load var from a txt

var="4"

how do i convert it to number 4?

i tried with Number and similar, but stupid thing just realizes that this is from a external file and will not change it !!

any ideas?

Help, My Number Is Trapped In A String And Cant Get Out
How do I convert a number trapped in a string ("2"?) I'm not that tallented when it comes to strings (assuming i'm tallented at anything!)

My Variable Is A String When I Want A Number?
Hi I have mc's named Day0, Day1, Day2 etc. I use this to extract the number from teh name

Fetch = _name.substring(3, _name.length);

it seems I end up with flash regarding Fetch as a string because when I do this to check

ArrayPos = Fetch+2;

flash puts the 2 onto Fetch as a string rather than doing addition.
How do I change this so that Fetch is a number?

thanks mark

How To Transfor String To Number
i work whit director and whit director you can only send string to flash

i would send a number to flash like 1 but i receive "1"
inside flash how i can transfor this "1" into 1

thx

Joining Number And String
I have a number which is part of a preloader, counting up percentage, it is in the variable "perc"
this works fine but when I try to append the percent sign with this script and display it in a textbox (variable nperc) I just get the number

nperc = perc +"%";

this is straight from a tutorial here at flashkit, does this need correcting?
tutorial is
http://www.flashkit.com/tutorials/Ac...60/index.shtml

thanks
mark

Copyright © 2005-08 www.BigResource.com, All rights reserved