|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using sendAndLoad variables outside the function
This might seem like a silly problem to most of them but being a newbie I have been scratching my head over this. Can anybody tell me how can I get the value of uid in this code outside the function so that my other functions can use it too.
I have the following code. But when I run the code. I get the two traces: 21 undefined Please inform me how can I get the userid value outside the function so that I can use it in all my other functions. //============================================= var userid; function getuid() { mailsettings = sharedObject.getLocal("UserSettings"); myData = new LoadVars(); mydata.username = username; mydata.pass = pass; myData.sendAndLoad("getuid.php",myData,"POST"); myData.onLoad = getuser; function getuser() { uid = this.useri; userid = uid; trace(userid); } trace(userid); } //============================================= Thanks for the help in advance. ![]() |
|
#2
|
|||
|
|||
|
userid is in the scope of your loadvars object so change to
trace(mydata.userid); or set userid as a var on the main timeline or a global var. |
|
#3
|
|||
|
|||
|
Thanks Jamie
Hello Jamie,
I don't know how to get it working. Can you just send me an example using flash php so that I can actually get it working that would be really great of you. Thanks in advance. ![]() |
|
#4
|
|||
|
|||
|
try
Code:
function getuid() {
mailsettings = sharedObject.getLocal("UserSettings");
myData = new LoadVars();
mydata.username = username;
mydata.pass = pass;
myData.sendAndLoad("getuid.php",myData,"POST");
myData.onLoad = getuser;
function getuser()
{
uid = this.useri;
_root.userid = uid;
trace(uid);
}
trace(userid); //this one should work - the var now exists on the main timeline
}
_root makes your code less portable though.....better would be to use _parent |
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > Using sendAndLoad variables outside the function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|