PDA

View Full Version : php & this.onEnterFrame causing pain!


CVO
02-03-2008, 11:16 PM
I am at a loss for this one really. It works on 1 part of the swf but not the other. The following is on a keyframe.

stop();
loadVariablesNum("dig.php", 0, "POST");

//this constantly checks to see if the PHP script has sent
//the variable 'checklog' back to the movie and directs accordingly
this.onEnterFrame = function() {
if (checklog == 5) {
gotoAndPlay(58);
delete this.onEnterFrame;
}
if (checklog == 6) {
gotoAndPlay(59);
delete this.onEnterFrame;
}
};Here's an example of the dig.php output: "status=Sorry, You are not a winner this time&checklog=6" (status is a dynamic text box in the movie).

Now I've checked and checklog is being received into flash but it won't execute the commands in the onEnterFrame. The weird thing is I have the exact same script at the start of my movie except it's for users logging in:
this.onEnterFrame = function() {
if (_root.checklog == 1) {
gotoAndPlay("sectorselection", 1);
_root.checklog = 0;
delete this.onEnterFrame;
}
if (_root.checklog == 2) {
gotoAndStop(3);
_root.checklog = 0;
delete this.onEnterFrame;
}
};It's identical and works fine. The only difference is loadVariablesNum is on a button movie clip (On release). I've tried putting the loadVariablesNum on a button for the script that isn't working but, just as I thought, it doesn't make a difference.

You can see the swf here (http://www.thetreasurehuntproject.com/game.swf). Log in with user "cvotest" and pass "cvotest" so you have credits. Once you pick your sector you will be taken to a screen which I have cluttered with dynamic textboxes showing all the vars including checklog. You will see checklog=0. Select your square and then press "Dig". The code above then executes. It will then update checklog to 5 or 6 from the php file but the movie won't gotoAndPlay.

I've asked for a lot of help on here recently and have learned a lot from it. I wanted to figure this one out myself but I've searched all day and tried many different things but I'm now starting to give up hope. Can anyone bail me out one more time? :)

CyanBlue
02-04-2008, 01:38 PM
I am not sure if I have said this or not, but I am saying it now just in case I have not...
Thou shall not use loadVariables(), period... Use LoadVars() object instead... :p
stop();

var _lv:LoadVars = new LoadVars();
_lv.variable = someVariableYouWantToPostToPHP;
_lv.onLoad = function (ok)
{
if (ok)
{
// This is where you should place your onEnterFrame code block...
if (this.checklog == "5") {
gotoAndPlay(58);
}
if (this.checklog == "6") {
gotoAndPlay(59);
}
}
else
{
// PHP script not loaded for some reason...
}
_lv.sendAndLoad("dig.php", _lv, "POST");
See if this gets you go any further...

CVO
02-04-2008, 02:23 PM
Hi CyanBlue. Thanks for the reply. I've done what you've said and got the following down:
stop();

var _lv:LoadVars = new LoadVars();
_lv.variable = square;
_lv.onLoad = function (ok){
if (ok){
this.onEnterFrame = function(){
if (this.checklog == "5") {
_root.gotoAndPlay(58);
}
if (this.checklog == "6") {
_root.gotoAndPlay(59);
}
}
}
}
_lv.sendAndLoad("dig.php",_lv,"POST");
The problem is I need to send 3 variables to php (user, pass and square). I've tried putting all of these in the "_lv.variable =" line but no dice. (I'm guessing that will probably raise a few laughs from the hardcore coders in here :p)

PS - I remember what you said about LoadVariables in another thread but I just can't get my head round why the loadVarNum worked earlier in the swf but not here.

CyanBlue
02-04-2008, 02:53 PM
That'd be something like this depending on what variables PHP is accessing...
_lv.user = user
_lv.pass = pass;
_lv.square = square;
I thought that I don't like to be called Cyan... I prefer CyanBlue... ;)

CVO
02-04-2008, 03:40 PM
Name fixed! The capital B threw me off ;)

I've now got the following code:stop();

var _lv:LoadVars = new LoadVars();
_lv.user = user;
_lv.pass = pass;
_lv.square = square;
_lv.onLoad = function (ok) {
if (ok) {
this.onEnterFrame = function() {
if (this.checklog == "5") {
_root.gotoAndPlay(58);
}
if (this.checklog == "6") {
_root.gotoAndPlay(59);
}
}
}
}
_lv.sendAndLoad("dig.php",_lv,"POST");Now I can see how that works and that should pass those 3 vars to the php file. Does it also pull in what the php outputs because it's still not working though and now the varible checklog isn't even being received in to flash.
Now I've tested the php file and it will output something like &prize=Noprizewon&pcode=notapplicable&status=Sorry, You are not a winner this time&checklog=6I've tried putting those variables in the script at the top too but it still doesn't work :(

CyanBlue
02-04-2008, 03:51 PM
No, you do not need an onEnterFrame loop if you use onLoad handler... That basically is the main reason why I said you should use LoadVars() object... ;)

Create a dynamic textField on the stage and give it an instance name of 'output_txt', and copy and paste what you get when you test the script...
Try this...
stop();

var _lv:LoadVars = new LoadVars();
_lv.user = user;
_lv.pass = pass;
_lv.square = square;
_lv.onLoad = function (ok) {
if (ok) {
output_txt.text += "prize = " + this.prize + "|\n";
output_txt.text += "pcode = " + this.pcode + "|\n";
output_txt.text += "status = " + this.status + "|\n";
output_txt.text += "checklog = " + this.checklog + "|\n";

if (this.checklog == "5") {
_root.gotoAndPlay(58);
}
if (this.checklog == "6") {
_root.gotoAndPlay(59);
}
}
}
_lv.sendAndLoad("dig.php",_lv,"POST");
Also, add the '&' at the end of the PHP output like this...
&prize=Noprizewon&pcode=notapplicable&status=Sorry, You are not a winner this time&checklog=6&

CVO
02-04-2008, 04:28 PM
Finally got what the problem was. The output after taking out the onEnterFrame loop was correct yet it would still not gotoAndPlay. There was a space after the checklog=6. I did check this before hand when I used GET and put the variables in the address line but it seems flash added the space and not the php which is why I didn't spot it! The solution was the "&" at the end of the php output. BINGO! :)

So in essence the original script worked fine (I knew it!). Such a simple thing causing hours and hours of head bashing agony! They should tell you this sort of thing in tutorials.

Once again CyanBlue - I am extremely grateful for pointing that out (I nearly missed it at the bottom of your post!). And I'll use the LoadVars object even though both scripts work and I will never misspell your name again :D

CyanBlue
02-04-2008, 04:32 PM
Yeah... If I see you using loadVariables() one more time, I will send you an invoice for my 2 cents... :p

Glad to help... :)