I've managed to get a User Login working for my website. The users details are kept on a separate .txt file in the same directory, called members.txt.
Here's how the text file looks:
The login works fine. See the numbers at the end of each line in the members.txt file? That's the user permission level. I've got a button (only accessed once logged in) that requires the user's level to be at least 5. As you can see, I've got two users so far, one is level 4, one is level 6. I've done this so I can test this section out.
My problem is that both users can still access the level 5 section. Here's the code on the button:
Code:
on (release) {
_root.userlevel = memberArray[ndx][3];
trace(_root.userlevel);
// what is the result ?
trace(typeof _root.userlevel);
// what is the result ?
trace(ndx);
// is this index number viable ?
trace(memberArray[ndx][3]);
// undefined ??
trace(_root.memberArray[ndx][3]);
// what result here with _root.prefix ??
if (_root.userlevel>="5") {
pages.gotoAndStop("special");
}
// end if
}
Also, from the traces in that code, I get the following results:
Code:
undefined
undefined
2
undefined
undefined
Can anyone see what I've done wrong here? Any help is greatly appreciated.
You have other problems there as well. I don't see where you load the textfield data to the movie. Then don't use scripts associated with buttons. Place all scripts on the main timeline.
myBut.onPress = function()
{
//function here
}
The reason why you get undefined is, because the data are not at _root.
- The right of the People to create Flash movies shall not be infringed. -
If you use the loadVariables function you need to wait until the loading is completed. You can go to the next frame or you can use event Dispatcher method or ASBroadcaster.
However, loadVariables is Flash 5 syntax. You should use LoadVars. i have attached some files.
- The right of the People to create Flash movies shall not be infringed. -
That works well but it's not quite what I'm after.
Once the user has logged in, they will see the same main screen as every other user. There's then a "Special" button that only certain levels of users can access. So the access level needs to be determined at that point, not at the login.
What are you using this for? Anything with private user information should never be handled with an external txt file.
The biggest problem you're having is by trying to store an array in the text file. Variables need to be URL-encoded in a url query fashion (example: myvar1=1&myvar2=2). You can't store arrays within the external file. Try to read variable "memberData." You'll notice that it's a string and not an array. That's why you're receiving undefined variables.
This should be handled (like Cancerinform said) with LoadVars, but instead of an external file, through a serverside (PHP, Perl, ect) request.
One note: For readability, say "if(something == false)", or the more efficient "if(!something)."
If you insist on using an external file, it will have to be XML.You can do it with an external text file, but you'll have to implement some special form of parsing to extract the data from the string.
Remember, though, XML and text files are cached, so anyone can go to their temporary files folder and have access to your whole database.
Last edited by Genesis F5; 05-16-2007 at 10:38 AM.