View Full Version : passing a variable inside a function
ldesign
04-21-2005, 10:15 PM
Hi all, here is the thing that is bugging me:
id = 1;
function somefunct(){
trace(id);
}
i need to pass the variable id inside the function ... anybody has an idea how ? (in this condition the trace prints undefined). Thanks in advance
andehlu
04-21-2005, 10:21 PM
function somefunct(var){
trace(var);
}
var = 1
somefunct(var)
CyanBlue
04-21-2005, 10:22 PM
'var' is reserved word, andehlu... ;)
andehlu
04-21-2005, 10:24 PM
right, bad example ;)
ldesign
04-21-2005, 10:25 PM
haha no problem, i got the idea ... let me try it ;)
ldesign
04-21-2005, 10:26 PM
People ... the situation is really bad ... it doesnt work :( ... any other ideas ?
andehlu
04-21-2005, 10:52 PM
paste yer code exactly
ldesign
04-21-2005, 11:11 PM
i found a "cure" seems like you have to call the function after you have set the id to 1 ... so this is the code that works:
id = 1;
somefunct();
function somefunct(){
trace(id);
}
// this wont work !!!
somefunct();
id = 1;
function somefunct(){
trace(id);
}
for me its quite strange ... sorry for wasting your time ... Thanks for the help ;)
andehlu
04-21-2005, 11:20 PM
ok thats why your not passing anything to the function like that
change it to:
function somefunct(){
trace(id);
}
id = "1";
somefunct(id); <--- this line calls the function and passes the vaue of id to it
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.