View Full Version : Passing Number variable to Flash
jamiller
11-10-2007, 02:44 PM
I need to know how to pass a number variable to a Flash movie from swfObject. Currently the variable being passed is being read as a string.
Anybody got any ideas?
Thanks,
Jeff
BLiZZaRD
11-10-2007, 05:46 PM
If you put your variable in quotes it is a string, no matter what the content is. The best way is correct scripting.
in Flash when you declare your var use this format:
var varName:Number = 0;
Then in your swfObject don't use quotes. just pass the number.
byvisual
11-28-2007, 06:25 PM
you must be kidding me!!!!!
Blizard!!!
have you ever tested what ur talking about that would always define your variable to be = 0 .
the way to do it jamiller is the following code.
var newVar:Number = Number(varName);
where newVar is the variable you will be using in the flash file and varName is the variable created by swfobject.
Have fun!!!!
contact me if u need further help!!
... ByVisual ...
BLiZZaRD
11-28-2007, 07:12 PM
Actually, no it won't. This will start the number as 0. It won't change until code or action change it.
Using your example, your number will always equal itself, you lose any math abilities. While this is good for a function where the number won't change, it loses any changeability based on other functions. You will always have to declare the variable as a whole, instead of a variable.
There are multiple ways to do many things, but if you want to code less, declare less. Now instead of setting a base number, and have the chance to change it based on multiple ways, you make him declare 2 variables, changing each anytime he wants to pass a new number.
var varName: Number = 0;
sets varName to 0. Want to change it?
with a button?
on (release) {
_root.varName += 1;
trace(_root.varName);
}
on a specific action?
onClipEvent (enterFrame) {
if (_root._currentframe == 1) {
_root.myNum += 1;
trace(_root.myNum);
} else {
_root.myNum == 0;
trace(_root.myNum);
}
}
and on.. and on...
So to answer your question, yes I do know what I am talking about, yes I do test my codes.. perhaps you can take the codes I have provided here and test them yourself?
If that would be too advanced for you I can provide an fla.
byvisual
11-28-2007, 09:27 PM
" I need to know how to pass a number variable to a Flash movie from swfObject. Currently the variable being passed is being read as a string.
Anybody got any ideas?
Thanks,
Jeff "
it has nothing to do with math!!!! its a variable being defined in html and thrown into flash. so what he needs is a simple fix that would change his variable from a string to a number. get it!!
by defining the variable as a number and setting it = 0 that does not work. because the variable sent in by swfObject is set once on the load of the movie. thats why the best way is to transform it into another variable which is also a number. then whatever you want to do from adding to subtracting to complex physics equations all is possible the important thing is that the loaded variable is a number.
I totally understand what you are trying to say!! it would have worked out if jeff is not using swfobject. get it!!!
please try it out using swfobject!!!
your way would never give him the initial value of the variable input in the swfobject.
boogyman
11-28-2007, 09:52 PM
you must be kidding me!!!!!
Blizard!!!
it has nothing to do with math!!!! its a variable being defined in html and thrown into flash. so what he needs is a simple fix that would change his variable from a string to a number. get it!!
...
...
I totally understand what you are trying to say!! it would have worked out if jeff is not using swfobject. get it!!!
please try it out using swfobject!!!
your way would never give him the initial value of the variable input in the swfobject.
Please watch your tensing and tone... Blizzard, nor anyone here does not deserve your tone whether he is correct or not. if you believe he is wrong then you can just state it, but the extra exclamation points are not necessary, and frankly very rude.
This is a volunteer, I will repeat volunteer, forum and thus he is not getting paid to help you, or jamiller, or anyone. We thank you for your opinions, and I am not saying Blizzard is right or wrong because I know nothing about flash, but I took offense to the blatant attack to a member that knows his stuff and is here day by day attempting to help people out. No one here is perfect, (not even you Twey and John :p ) so in the future just please watch how you respond to the question(s) here.
now from a general coding stand point,
I need to know how to pass a number variable to a Flash movie from swfObject. Currently the variable being passed is being read as a string.
this seems to be a problem of type casting? just as you stated byvisual
as I stated before I do not know anything about flash, but if there is a method by which you can type cast the string into a number, in theory that should solve the question
in either event though Jamiller, it would probably be best if you could possibly show us some actual code wrapping it in [code] tags (for formatting)... I know many people have some skepticism about releasing their code, however you do not need to release the whole thing, just the snippet causing the problem.... we would nis dealing with this problem
eed both the user-input and the variable-processing code please.
byvisual
11-29-2007, 01:09 AM
your right, boogyman
now reading it over i was a bit tense in my language. and i do tend to use allot of exclamation marks!
never meant to offend anybody but on all sides sorry if i did.
sorry blizzard for the high tone of replies but please look into what i was talking about, and if you do have other solutions please let me know about I'm always happy to learn new ways for things.
...ByVisual...
BLiZZaRD
11-30-2007, 12:07 AM
There are many ways to do such, and as the OP states he doesn't want a string read as a number, his number is being read as a string. The basic cause for thisis Flash reads variables based on the code inside thefla, if it is en-quoted ("like this") it is a string. If there are no quotes it is a value (in the OP's case, a number).
Based on this knowledge, the OP most likely has a number variable inside his AS coding.
Now, he is using SWFObject to exploit this number in some way, and if it is a number it is probably a counter, a score, or some other mathematical increase/decrease for a game or a hit counter, etc. Which means this number will change, based on the actions of the user or the page it is on, etc.
If he is just passing a variable from HTML to the Flash he would be better off with FlashVars anyway.
It also depends on the version of Flash being used. All of this, both your and my replies are based on speculation as to what the OP really wants. Until we get more information we can just post our thoughts and let him try all of them until one works, and then hopefully he will post back telling one of us thanks, at which point we can figure out more.
That's usually the way it works.
As far as the tone and use of exclamation... To each his own.
sunnyday
12-20-2007, 01:54 AM
Flash is unfathomable for a beginner.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.