PDA

View Full Version : loadVariables


cribeaud@predict.ch
07-29-2001, 10:03 PM
Hi,

I am using the following script to load 2 variables: 'text' and 'v' in the target "/keyword3":

onClipEvent (load) {
var i = 3;
// if variables already written in URL, use
// loadVariablesNum
loadVariablesNum ("http://www.predict.ch/flash/keyword.php4?i="+i,"/keyword"+i);
xPosInit = getProperty("/keyword"+i, _x);
xPos = xPosInit;
}
onClipEvent (enterFrame) {
if (Math.abs(xPosInit-xPos)<550) {
xPos += v;
setProperty ("/keyword"+i, _x, xPos);
}
}

If I type "http://www.predict.ch/flash/keyword.php4?i=3" in the url, I get the following text: "text=Knowledge+Discovery&v=5". But neither the variable 'text' nor the variable 'v' seems to have been loaded in the instance "/keyword3". I would be very grateful if someone could help me. All files reside at http://www.predict.ch/flash/.
Yours faithfully,

christian

Jesse
07-30-2001, 07:36 AM
You're targetting an MC instance but using loadVariablesNUM which is for a level target. Use just loadVariables:
onClipEvent (load) {
var i = 3;
// if variables already written in URL, use
// loadVariablesNum
loadVariables ("http://www.predict.ch/flash/keyword.php4?i="+i, "\"/keyword\"+i");
xPosInit = getProperty("/keyword"+i, _x);
xPos = xPosInit;
}
onClipEvent (enterFrame) {
if (Math.abs(xPosInit-xPos)<550) {
xPos += v;
setProperty ("/keyword"+i, _x, xPos);
}
}
Normal mode can be helpful. I noticed the error immediately because the LoadVars target was set to Level in the drop down.

cribeaud@predict.ch
07-31-2001, 12:42 PM
Thanks a lot! I now get both variables. I still have a problem with the following lines of code:
if (Math.abs(xPosInit-xPos)<550) {
xPos += v;
setProperty ("/keyword"+i, _x, xPos);
}
If I write explicitly 5 instead of v (xPos += 5), it works. Otherwise the v's value is appended (like a string!) and I get a "NaN" value for the "xPosInit-xPos"-operation. I tried to use one or more Number functions to make "xPos += v" an arithmetical operation but the problem persists. What is wrong? Greetings,

christian

Jesse
08-01-2001, 07:44 AM
if you're loading v from a text file you have to remember it comes in as a string:
v = Number(v); will fix that

cribeaud@predict.ch
08-01-2001, 09:55 AM
Hi Jesse,

I have found out what the problem was and I think it is an interesting one. Your suggestion (v = Number(v)) did not work. I had already tried it before. The problem is a lasting white space after the string: "text=Knowledge+Discovery&v=5"
With a trim()-funktion in the PHP page, everything get alright. Thanks a lot for your help. Have a nice day,

christian