A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: sendAndLoad (can send but not load...)

  1. #1
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784

    sendAndLoad (can send but not load...)

    Ok, well I have spent the last 45 minutes reading old threads about sendAndLoad, but cannot seem to figure it out. I am doing it twice. The first time, I don't really want to sent anything, but only receive a couple variables which I am pullin from a database. The second time, I only send variables and do not receive any. The second time works just fine. Here is the AS code and the PHP code that I use to try and receive variables.
    Code:
    function receiveVariables () {
    	var_text.text = "loading";
    	varsIn.onLoad = function (success) {
    		if(success) {
    			background.gotoAndStop(this.color);
    			if(!this.owner) {
    				save._visible = false;
    			}
    			var_text.text = this.color;
    		}
    	}
    	varsOut.sendAndLoad("../sendColor.php", varsIn, "POST");
    }
    PHP Code:
    mysql_connect($_server,$_user,$_password);
    @
    mysql_select_db($_database) or die( "Unable to select database");
    //color will actually retrieve $_frame, but to simplify things I changed it to 1
    echo "color=1";
    mysql_close(); 
    I appreciate any help. This is really getting to me.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  2. #2
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    At a quick glance I'd say it's 1 of two things:

    Either A) You're scope "this.color" is wrong (try absolute of _root.varsIn.color);
    or B) You don't seem to be passing a success variable back as true, so it would seem as that the conditional is never going off. Have you tried tracing inside the if(success) conditional?
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  3. #3
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    Yes, my text_box displays "undefined". Also the absolute path didn't work.
    Last edited by TheLostGuru; 06-06-2007 at 06:50 PM.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  4. #4
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    I did mean tracing in general, just to see if the conditional is actually passing it's check and executing.

    Code:
    if (success) {
        trace("All's well.");
        ....
    }
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  5. #5
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    Well I can't trace because I am testing it on a server, but I just changed it so the text box didn't look at this.color, but "DO I FREAKING WORK?" and yes it showed up.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  6. #6
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    If that doesn't work, you may need to switch methods. Generally I use loadVariables() for loading, and sendAndLoad for sending. Typically I use this method for game high scores (with the exception of my map editor app), but here's how I run through that. Again, sendAndLoad for sending data, and loadVariables for retrieving data.

    Code:
    function sendScores(userName:String, userScore:Number) {
    	var sendScore:LoadVars = new LoadVars();
    	sendScore.userName = _root.username;
    	sendScore.myScore = _root.score;
    	sendScore.table = "table";
    	var score_result:LoadVars = new LoadVars();
    	score_result.onLoad = function(success:Boolean) {
    		if (success) {
    		} else {
    			trace("Error connecting to server.");
    		}
    	};
    	sendScore.sendAndLoad("someUrlHere"+Math.random(), score_result, "POST");
    }
    sendScores(_root.username, _root.score);
    //...
    function getScores() {
    	loadVariables("someUrlHere"+Math.random(), scoreboard);
    	for (var sc = 1; sc<11; sc++) {
    		scoreboard["username"+sc].text = scoreboard["username"+sc];
    		scoreboard["score"+sc].text = scoreboard["score"+sc];
    	}
    }
    getScores();
    Last edited by ImprisonedPride; 06-06-2007 at 07:17 PM.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  7. #7
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    Nothing... Here's my code
    Code:
    loadVariables("../sendColor.php", varsIn);
    background.gotoAndStop(varsIn.b_color);
    if(!this.owner) {
    	save_mc._visible = false;
    }
    var_text.text = b_color;
    var_text.text still says it is undefined

    [edit] Does loadVariables require an "onLoad"?
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  8. #8
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    I think the varsIn function should be declared outside the receiveVariables function.

    Heres an example,
    PHP Code:
    //The loaders that will send and retrieve our variables
    var sendVars:LoadVars = new LoadVars();
    var 
    getVars:LoadVars = new LoadVars();

    //Function is called when getVars recieves values from the PHP script 
    getVars.onLoad = function(success) {
        if(
    success) {
             
    _root.gotoAndStop(this.colour);
            }else{
                 
    trace("ERROR OCCURRED");
            }
    }

    function 
    receiveVariables () {
        
    //Declare the variables you wish to send <-- Examples
        
    sendVars.playername this.submitscore;
        
    sendVars.playerscore this.playername;

        
    //Send the variables to the PHP script and wait for a reply
        
    sendVars.sendAndLoad("sendScore.php?c"+new Date().getTime(), getVars);


  9. #9
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    Ok, big changes.

    Problem #1
    You can't leave mysql_close() if you don't ever connect to the database.

    I changed the paths in sendAndLoad from ("../blahblah", varsIn, "POST") to the full path ("http://blahblah", varsIn, "POST") and everything worked like a charm. Now when I load the swf on the web, it goes back to saying that it is undefined. Anyone know why, things would change from running an swf offline and then one embedded online?

    [EDIT] I cleared my cache and it works fine. I didn't know that flash wouldn't find the real file and not the one that has been cached...
    Last edited by TheLostGuru; 06-06-2007 at 08:53 PM.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  10. #10
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Problem #1
    You can't leave mysql_close() if you don't ever connect to the database.
    mysql_connect($_server,$_user,$_password);
    @mysql_select_db($_database) or die( "Unable to select database");

    But you do? Ow and its a bad habit to use @ before a function call. It escapes any errors. That could be the problem. Its not contecting too the database and you wouldn't know.

  11. #11
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    oh... didn't know that. I'm brand new to this PHP stuff. So I shouldn't use "@'s"? Also, problem. Go to http://tlgames.siteburg.com/welcome.htm. Change the color and click save. Now refresh the page. The background is supposed to go back to the color you saved as. However, it won't unless you clear your cache and refresh the page. How do I work around this?
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  12. #12
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    Nevermind about the last question. I just added a ?no_cache="+Math.random() to the URL's and it seems to work. (thanks to MD )

    Thanks for the help hooligan and IP.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  13. #13
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    It might seem obvious, but what does no_cache do? I thought that was the point of adding Math.random() the url, to force the browser to make a new version on every visit.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  14. #14
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Yeah your right IP "sendScore.php?c"+new Date().getTime() generates a random number that will never be duplicated so its a new page every time and stops caching. Its the same thing as the no_cache version except Math.random has a very slight chances of creating the same number

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center