waiting for getURL, and onLoad question....

  • TsX
  • Graduate
  • Graduate
  • User avatar
  • Posts: 167

Post 3+ Months Ago

I am working with Flash/PHP integration, and I am learning actionscript from the ground up so thats where I'll have most of my questions now.

I am passing variables through a url for php.

ex. http://lwww.site.com/test.php?variable=sent

I got that working the way I Want it, I figure I'll give the sendAndLoad function awhile before I touch it.

Now this variable will update something in my database, but the problem is, the update is slow compared to how fast I Can get the next frame in flash.

I'll try to give an example, forgive my novice skills:

Code: [ Select ]
button.onPress = function() {
  getURL("www.site.com/test.php?variable=sent");
  gotoAndPlay(2):
}
  1. button.onPress = function() {
  2.   getURL("www.site.com/test.php?variable=sent");
  3.   gotoAndPlay(2):
  4. }


and where the goto leads to:

Code: [ Select ]
loadText = new LoadVars();
loadText.load("http://www.site.com/data.php");
loadText.onLoad = function() {
    updatedVar = this.phpGeneratedVar;
};
  1. loadText = new LoadVars();
  2. loadText.load("http://www.site.com/data.php");
  3. loadText.onLoad = function() {
  4.     updatedVar = this.phpGeneratedVar;
  5. };


now the .onLoad waits for the variables to load correct? but what about waiting for the URL to load? I could make a pause or something, but its not what I'm looking for. Any help?

/edit/ maybe I should be considering sendAndLoad?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Dano
  • Novice
  • Novice
  • User avatar
  • Posts: 22

Post 3+ Months Ago

Hi TsX:

I think, that you are confused, about the mean of LoadVars. I try to explain it.

For example, if you want to send a Variables to php, and wait for the answer, this is the AS, that you need, put it in the first frame of your movie:

Code: [ Select ]
function enviar(){
 var myVars:LoadVars=new LoadVars();
 myVars.name="Jhon";//So, you send the variable "name"
 myVars.email="mail@domain";//So, you send the variable "email"
 myVars.onLoad=function(){//Wait, for the answer
  trace(this.Answer);
 }
 myVars.sendAndLoad("pagina.php",myVars,"POST");
}
boton.onRelease=function(){//boton if a instanceName of a button in your Stage
enviar();
}
  1. function enviar(){
  2.  var myVars:LoadVars=new LoadVars();
  3.  myVars.name="Jhon";//So, you send the variable "name"
  4.  myVars.email="mail@domain";//So, you send the variable "email"
  5.  myVars.onLoad=function(){//Wait, for the answer
  6.   trace(this.Answer);
  7.  }
  8.  myVars.sendAndLoad("pagina.php",myVars,"POST");
  9. }
  10. boton.onRelease=function(){//boton if a instanceName of a button in your Stage
  11. enviar();
  12. }


And the PHP, like this:
Code: [ Select ]
<?
echo "&Answer= Hi! ".$_POST["name"]." Your email is: ".$_POST["email"];
?>
  1. <?
  2. echo "&Answer= Hi! ".$_POST["name"]." Your email is: ".$_POST["email"];
  3. ?>


Have a nice day! :D
  • TsX
  • Graduate
  • Graduate
  • User avatar
  • Posts: 167

Post 3+ Months Ago

Ok, a lot of it is starting to make sense now, just some questions. Whats happening exactly when you do this:

var myVars:LoadVars=new LoadVars();

And how does myVars.name already exist? Or is that called to? If you could clear that up please.
  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 861
  • Loc: BKNY

Post 3+ Months Ago

var myVars:LoadVars=new LoadVars();

tell flash to
a) declare a new variable called myVars
b) make that variable a LoadVars
and c) creates myVars as an instance of the LoadVars object, which can then be used to send information

myVars.name doesn't already exist... by writing the code
Code: [ Select ]
myVars.name="Jhon";

you're calling it into existence... and telling it what it is...

hope i got all that right and i hope it's helpful...

peace
  • TsX
  • Graduate
  • Graduate
  • User avatar
  • Posts: 167

Post 3+ Months Ago

yes, you hit everything on the knob. final question about it. I was trying to look it up instead, but I am still unsure:

myVars.onLoad=function(){//Wait, for the answer
trace(this.Answer);
}
myVars.sendAndLoad("pagina.php",myVars,"POST");

how is that waiting for the php page to fully load and update any database values that need be. explaining it step by step again would be helpful again, thanks for that roarmeow
  • Dano
  • Novice
  • Novice
  • User avatar
  • Posts: 22

Post 3+ Months Ago

Ok, the onLoad event, is a low level code event, that Flash uses for know when a File exaclty finish, the download.

So, you can do a lot o jobs.

For example, the way for you insert a row in a DB is, step by step:

1.- Write this code in your Flash movie.
Code: [ Select ]
function Save(){
 var myVars:LoadVars=new LoadVars();
 myVars.name="Jhon";//So, you send the variable "name"
 myVars.email="mail@domain";//So, you send the variable "email"
 myVars.onLoad=function(){//Wait, for the answer
  trace(this.Answer);
 }
 myVars.sendAndLoad("save.php",myVars,"POST");
}
boton.onRelease=function(){//boton if a instanceName of a button in your Stage
Save();
}
  1. function Save(){
  2.  var myVars:LoadVars=new LoadVars();
  3.  myVars.name="Jhon";//So, you send the variable "name"
  4.  myVars.email="mail@domain";//So, you send the variable "email"
  5.  myVars.onLoad=function(){//Wait, for the answer
  6.   trace(this.Answer);
  7.  }
  8.  myVars.sendAndLoad("save.php",myVars,"POST");
  9. }
  10. boton.onRelease=function(){//boton if a instanceName of a button in your Stage
  11. Save();
  12. }


2.- And the php:

Code: [ Select ]
<?
include("func.php");
$link=Conection();//It is a function, that you defined in "func.php" for conect to mysql_db
$sql="insert into users (name,email) Values";
$sql.="( '".$_POST["name"]."' , '".$_POST["email"]."' );";
if(mysql_query($sql,$link)){
  echo "&Answer=true";
}else{
 echo "Error inserting.. ".mysql_error();
}
?>
  1. <?
  2. include("func.php");
  3. $link=Conection();//It is a function, that you defined in "func.php" for conect to mysql_db
  4. $sql="insert into users (name,email) Values";
  5. $sql.="( '".$_POST["name"]."' , '".$_POST["email"]."' );";
  6. if(mysql_query($sql,$link)){
  7.   echo "&Answer=true";
  8. }else{
  9.  echo "Error inserting.. ".mysql_error();
  10. }
  11. ?>


:)

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.