Help Casting A String To A Number
I've got a String value I'm trying to pass into a beginFill() function, but it's not happy with a String and gives me this error: "1067: Implicit coercion of a value of type String to an unrelated type uint. I've tried casting using "hexString as Number" but that turns my pretty "0xFFFFFF" into something like 106425. Any suggestions on how to give beginFill a value that's originally a String? ActionScript Code: private function createBG(hexString:String):void { // this doesn't work - it turns my "0xFFFFFF" format into a numeral //var bgColor:Number = hexString as Number; var bg:Shape = new Shape(); // pre-defined colored bg, starting at point 0, 0 bg.graphics.beginFill(bgColor); bg.graphics.moveTo(0, 0); bg.graphics.lineTo(stage.width, 0); bg.graphics.lineTo(stage.width, stage.height); bg.graphics.lineTo(0, stage.height); bg.graphics.lineTo(0, 0); addChild(bg); }
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 02-23-2008, 05:09 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Help: Casting String Gotten From Xml To A Number Type
Hi all,
I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.
For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.
Next it creates a new var of Number Type and assigns it the Number value of the string in global var.
It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX
However the Node doesn't move and this is the output I get from the traces
Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN
I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ides?
-------------------------------------------------------------------------------------------------------------------
Attach Code
butNodeSet.onRelease = function() {
trace ("Start Node is at x = " + mcStartNode._x);
trace ("nod_topLeftX is " + nod_topLeftX);
var SNtopLeftX:Number = Number(nod_TopLeftX);
trace ("StartNode TopLeftX = " + SNtopLeftX);
mcStartNode._x = SNtopLeftX;
}
Help: Casting String Gotten From Xml To A Number Type
Hi all,
I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.
For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.
Next it creates a new var of Number Type and assigns it the Number value of the string in global var.
It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX
However the Node doesn't move and this is the output I get from the traces
Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN
I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ideas?
------------------------------------------------------------------------------------------------------------------- This is my Code
butNodeSet.onRelease = function() {
trace ("Start Node is at x = " + mcStartNode._x);
trace ("nod_topLeftX is " + nod_topLeftX);
var SNtopLeftX:Number = Number(nod_TopLeftX);
trace ("StartNode TopLeftX = " + SNtopLeftX);
mcStartNode._x = SNtopLeftX;
}
AS3 Calculating And Number Casting
Hi everyone...
Since my project's code majority is some math routine, i have to kno the exact actionscript flow of makin calculations.
My usual formulas are mixes of ints and Number.
I've made severl tests like this:
Code:
var a:int = 2;
var b:int = 3;
var c:int = a/b;
trace(c);
// 0
Code:
var a:int = 2;
var b:int = 3;
var c:Number = a/b;
trace(c);
// 0.6666667
Code:
var a:int = 2;
var b:int = 3;
var c:int = Math.ceil(a/b);
trace(c);
// 1
So once after that I've made some conclusions, that first calculation is made in floats (Numbers), after that it's casted to the type (int or Number) which is requerd by the left hand operator, or function arguments place.
Am I right? Can anyone get me some accurate scheme of how those calculating things are performed? Or link? Thank you!
Number Casting Problem
Hi there,
I'm trying to add two numbers. One is a variable I keep on the server, the other is one I get from a client..
Seeing as the calls from the client are all casted to strings (I think so at least). Is there any way I can cast them to a number in my server so I can add them instead of concatinating them as string...
plan is to make 5+5=10 instead of 55 ;-)
Thanks in advance
Bart
Casting A String To An Object
I'm having trouble passing an object parameter using a string concatenation in a for loop...
in the for loop, I duplicate movieClips, copying a movie called "glass" and try to register it's speeds with the register() function below.
for (i = 1; i <= numObjects; i++) {
duplicateMovieClip(glass,"glass" + i, i);
register("glass" + i,20,20,20);
}
function register(object, xspeed, yspeed, rspeed) {
objects.push(object);
object._xspeed = xspeed * (2 * Math.random() - 1);
object._yspeed = yspeed * (2 * Math.random() - 1);
object._rspeed = rspeed * (2 * Math.random() - 1);
}
unfortunately, when passing tmp as "glass" + i, register thinks its a string, not an object. The object appear on stage, but doesn't move. If I hard code register() passing in as register(glass2,20,20,20) it does move.
How do I cast the string I pass in as an object?
Casting A String Into A Function
Hi,
I would like to convert a String to a function:
Code:
public function Init(command:String)
{
//i need to call the handleHowTo() function from here base on the command String
}
public function handleHowTo()
{
trace("yes");
}
Init("handleHowTo");
How can I convert the command:String to a function to call the function handleHowTo() ? is there a way to cast a String into a Function ???
Thanks ;)
Casting String To Uint
Hello,
Does anyone know how to cast a string into a uint?
I have tried some along the lines of the following:
var myStr:String = "0x000000";
var myUint:uint;
myUint = uint(myStr);
But i keep getting an error stating that there is a mismatch in variable types or i get a value of '65280' when I trace myUint. I understand that uint is a positive integer but i need to accept a string for the colour value and need to convert it to a string for use.
Any suggestions and correct answers are welcome. I will post or indicate the working solution once this problem has been solved.
Thanks in advance to everyone,
Lee
Edited: 11/26/2008 at 03:42:18 AM by leej_w
Flash MX Casting Problems: String Value To Object._name?
I am importing delimited from asp that I have split into an array.
I'm trying to tell a movie clip instances to play with the move clip name based off the [i] "numbers".
I can get setproperty to render the visibility property however I can seem to get the casting of the variable right in order to tell the movie to play.
Example of what I need to work.
Array [0] //Output: mc25 which is also the name of a mc instance.
newmc= Array[0];
newmc._play;
The above doesn't work and I know that is somehow related to newmc being a string value. How do I convert the sting back to a mc._name?
Also:
[-----Works---------------------------------------------------------]
chec=b25;
bog= chec;
group=bog;
setProperty(group,_currentframe,group.gotoAndPlay( group._currentframe+1));
displaytextbox=group;------------------------------------------------------------------------
[----Doesn’t-------------------------------------------------------]
chec=b25;
bog=String(chec);
group=bog;
setProperty(group,_currentframe,group.gotoAndPlay( group._currentframe+1));
displaytextbox=group; -----------------------------------------------------------------------
Any Ideas?
Problems With Casting Or String (literals?), And Dynamic References
Can someone please tell me the difference in these three code chunks?
1) is it casting a string, or incorrect syntax?
2) this works,
3) if #2 works as a plain "" string, then what cases would prompt the string to need String("whatever") ?
if menu_item_txt is a textField at _level0:
1)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this[String(menu_item_txt) + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
2)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this["menu_item_txt" + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
3)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this[String("menu_item_txt") + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
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?
[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.
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 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
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?
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
Loaded String To Number?
Problem:
As I load variables from an external file, I have one var which is assigned a value of a number, let's say, 4. When the var loads into the movie, I need to do numeric operations with it, but I cannot, since the var is considered a string (has escapes included, a "4
" or so in debugger). When I Int(var) it, the value becomes 0.
Is there any better way to make it numeric?
|