Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-06-2012, 06:03 PM   #1
trecords
Registered User
 
Join Date: Aug 2012
Posts: 4
Red face My code not posts data to url

Hi,

I have wrote my first little code on Actionscript Actually i am an php developer but i have started with flash today :S so i have created this code:
ActionScript Code:
function post_results(userid,session,score) {     // Post data to database     var loader:URLLoader = new URLLoader();     var req:URLRequest = new URLRequest("example.com/post.php");     req.method = URLRequestMethod.POST;     var postData:URLVariables = new URLVariables();     postData.uid = "000023542543";     postData.ses = "w6r4gt46wrtg4w3trg1ew3rt5h465tw";     postData.scr = "5868";         req.data = postData;     try {         loader.load(req);         trace("Data Sent");         trace(req.join());     } catch (error:Error) {         trace("Unable to load requested document.");     }  }

I have added some demo data in "postData" for to debug to see if it can post them correctly. Remote server is php based application which stores received data into txt file in server.
See this code and check please why what is problem there.

Turkel.
trecords is offline   Reply With Quote
Old 08-06-2012, 07:06 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,822
Send a message via Skype™ to henke37
Default

Data loading is asynchronous, you have to wait for the loading to complete. Listen for the Event.COMPLETE event.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 08-06-2012, 07:06 PM   #3
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

Does this work any better?
Any errors?
ActionScript Code:
function post_results(userid,session,score):void {     var postData:URLVariables = new URLVariables();     postData.uid = userid;     postData.ses = session;     postData.scr = score;         // Post data to database     var loader:URLLoader = new URLLoader();     var req:URLRequest = new URLRequest("example.com/post.php");     req.method = URLRequestMethod.POST;     req.data = postData;         try     {         loader.load(req);         trace("Data Sent");         trace(req.join());     }     catch (error:Error)     {         trace("Unable to load requested document.");     } } post_results("000023542543","w6r4gt46wrtg4w3trg1ew3rt5h465tw","5868");
[afz]snickelfitz is offline   Reply With Quote
Old 08-08-2012, 02:31 PM   #4
trecords
Registered User
 
Join Date: Aug 2012
Posts: 4
Default

I got his error:
Symbol=ftc_game, layer=end game, frame=1, Line 1 '{' expected
Line 1 is:
function post_results(userid,session,score):void

Not sure why it says this error because there are alsready { symbol on next line, i have moved it to first line end also but still got same error.
I have wrote new code:
PHP Code:
function data_sent () {
    
trace("Data Sent");
}

function 
post_results(userid,session,score) {
    var 
postData:URLVariables = new URLVariables();
    
postData.uid '00031653156431'//userid;
    
postData.ses 'gtrgrwe6gt46e54hy6e5hy'//session;
    
postData.scr '5487'
    
    
// Post data to database
    
var loader:URLLoader = new URLLoader();
    var 
req:URLRequest = new URLRequest("/site/post.php");
    
req.method URLRequestMethod.POST;
    
req.data postData;
    
    try
    {
        
loader.addEventListener(Event.COMPLETE,this.data_sent());
        
loader.load(req);
    }
    catch (
error:Error)
    {
        
trace("Unable to load requested document.");
    }


This code uses Event.COMPLETE function but still not works

Help me please how to solve this.

Turkel.
trecords is offline   Reply With Quote
Old 08-08-2012, 02:56 PM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,822
Send a message via Skype™ to henke37
Default

Do NOT call the listener function while adding it. Also, the listener function has the wrong prototype. It must take exactly one argument, the Event object.

Also, try typing your arguments, the type information is good.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 08-08-2012, 03:02 PM   #6
trecords
Registered User
 
Join Date: Aug 2012
Posts: 4
Default

Quote:
Originally Posted by henke37 View Post
Do NOT call the listener function while adding it. Also, the listener function has the wrong prototype. It must take exactly one argument, the Event object.

Also, try typing your arguments, the type information is good.
Sorry but couldn`t got what you mean. How to call listerner function? can you give example plz.
trecords is offline   Reply With Quote
Old 08-08-2012, 03:15 PM   #7
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,822
Send a message via Skype™ to henke37
Default

You don't. That's how. Flash calls it, not you.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 08-08-2012, 03:38 PM   #8
trecords
Registered User
 
Join Date: Aug 2012
Posts: 4
Default

But how? can you rewrite this please.
trecords is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:49 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.