Hello. I have long time trying to achieve this. I have this riddle/enigmatic html game, with a flash button for entering the keys to suceed to the next level.
All the buttons from all levels are working 100% because the password variable is written in the same flash button. But the thing comes when in the level 5, i want to have random keys, that only will be shown when playing a PONG game. That works too, when you beat the PONG game, a random key/password/code, appears. The problem is loading the vars for the button.
I have a button with "btn" as instance name, and an input text field with "passW" as variable name. The keys are in a text file named Passwords2.txt
The keys are written like this:
The only thing that works is, if you type anything wrong, it goes to error.htm. That's ok. But when you type the correct keys (adobe, atari, flash...) it goes to error.htm TOO! Also, when there is nothing in the input text box, and you press the button, it goes to nivel6.htm!!!! Without writing any key!
Problem is that you gave your textfield a Variables Name, and in it will the formatting be included, so it will rather look something like this:
Code:
<TEXT type="something" size="2">myPassword</TEXT>
instead, give it an Instance Name, 'cause then you can access all of the text field's properties, so just target its .text property to retrieve the content of your text field:
I achieved to Load the variables correctly, but I can only view them with "traces".
Actionscript Code:
varReceiver = newLoadVars(); // load the variables from the text file varReceiver.load("Passwords2.txt"); // trigger something - when the variables finish loading varReceiver.onLoad = function(){ //the variables have finished loading //do something... trace(this.myPassword); // you use the this keyword to call the variables stored in the object varReceiver trace(this.myPassword2);
};
How do I import them now into the first frame or something, so I can call them as:
Also i tried to create 2 new dynamic text boxes, to load the variables there, so the
Actionscript Code:
if(passW.text == newVar ){
call that new variable, and the new variable load the external variables as this:
Actionscript Code:
//The dynamic text box is called "Caller" as variable name, and the code goes likes this: if(passW.text == Caller || passW.text == Caller2 ){
//And the new Variable calls the external variables on the .txt file Caller = this.myPassword; Caller2 = this.myPassword2;
Nothing either. I'm very fustrated with this, because I have another thing that i achieved, loading external "Random" text from a .txt file, and that works 100%. If I put the external variables, in the firstframe, the proyect works 100%. I succeed in loading the external variables, as you can see, i can view them with "TRACES" in the output panel, but I CAN NOT use them in the code. Thanks for the help, hope somebody lead me in the right direction.
Send the values to _root, and then call the same values in the if statement:
Actionscript Code:
varReceiver = newLoadVars(); // load the variables from the text file varReceiver.load("Passwords2.txt"); // trigger something - when the variables finish loading varReceiver.onLoad = function(){ //the variables have finished loading //do something... _root.myPassword = this.myPassword; // you use the this keyword to call the variables stored in the object varReceiver _root.myPassword2 = this.myPassword2;
OKAY people. I did it. Just for the record, and for anyone who tries to load variable from a .txt file, do ALL THE PREVIOUS CODE ABOVE
Actionscript Code:
varReceiver = newLoadVars(); // load the variables from the text file varReceiver.load("Passwords2.txt"); // trigger something - when the variables finish loading varReceiver.onLoad = function(){ //the variables have finished loading //do something... trace(this.myPassword); // you use the this keyword to call the variables stored in the object varReceiver trace(this.myPassword2);
Oh, good that you've sorted the problem, but adding "this" depends completely on the structure of one's flash file, you just gotta learn how path works in flash, and once you've grasped that, it's really easy to tell when to add the prefix "this", "_parent" or "_root"
17 Years old boy, who loves the Computer Technology
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
No. It was 6am, and I didn't test the code enough because i was sleepy. It isn't solved yet :'( , how do I put this thread as "unsolved" again?
I thought putting "this" before the input textbox instances name in the "if" script have done the thing, but not. Now, if you press the button "btn" without typing anything, it goes to nivelseis.htm. !!! That's nuts!!! I return to the "fustrated" mood again
I realized where the problem is. I put the variable trace in the onPress of the button, and I got the variable "undefined" , that means the problem is "location". I don't know where the variables are loaded, i tried _global, _level0, _root, _parent, this, and nothing. It's just that, once I achieved to identify the location where are the variables loaded, voilá! It will works.
Note: I'm noticing that the variables are loaded in the varReceiver object, how can I call the variable there? If is not with the varReceiver object, then it has to be something like _level0, _root, etc.
Notice in your trace that there is a linebreak (enter/blank space) between each traced variable from the text file, this is not a coincidence, there's actually a linebreak/enter included in each variable, which is preventing you from entering the correct password due to the enter/linebreak included at the end. I don't know why this is happening, but to remove the linebreaks, simply before every &, place your pointer before it, and press backspace once, and you'll see that nothing is removed, but in reality, a hidden linebreak/enter is removed, or just copy and paste this line to your text file:
Although, your code will still not work, because in your Button code, you are referring your password as, this.myPassword, which is wrong. When you type, this.myPassword in the LoadVars onLoad event, you are actually saying, varReceiver.myPassword, so this in this case, inside your LoadVars, merely refers to the LoadVars itself, because the received variables are saved inside that object. When you type this.myPassword in onPress event for your button, this then refers to your button, so it actually says, btn.myPassword, but you have no variables saved inside your button, which is why you're code is not working either!
To solve it, as stated earlier, saved the passed variables from the txt file, to other variables in Flash which are accessible throughout the whole level/path. Just save each passed variable to its own variable in Flash:
Now solved FINALLY!!!!!!!!!!!!!!!!!!!!!!!!!!!! Thanks to Nig 13.
Actionscript Code:
if(passW.text == varReceiver.myPassword)
didn't work, but
Actionscript Code:
if(passW.text == myPassword
without the "varReceiver" object, that worked 100%, but the problem was in the .txt file. As you said, i delete the spaces between the variables on the text file, joining them together