We Recommend

Essential ActionScript 3.0 Essential ActionScript 3.0
The book focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.


Posted By

chrisaiv on 01/10/08


Tagged

as3


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

fukami
arala22
Akuma99
outbox


AS3: Sending Data using POST


Published in: ActionScript 3 


This is the AS3 way that replaces getURL. This function also shows how to pass variables to a PHP $_POST['params'].


  1. var bg_mc:MovieClip = new MovieClip();
  2. bg_mc.width = 320;
  3. bg_mc.height = 240;
  4. bg_mc.x = 0;
  5. bg_mc.y = 0;
  6. bg_mc.buttonMode = true;
  7. bg_mc.addEventListener(MouseEvent.MOUSE_DOWN, visitSite);
  8. addChild(mc);
  9.  
  10. function visitSite(e:MouseEvent):void {
  11. var url:String = "http://www.google.com";
  12. var request:URLRequest = new URLRequest(url);
  13. var variables:URLVariables = new URLVariables();
  14. variables.sessionTime = new Date().getTime();
  15. variables.sessionUser = "guest";
  16. request.data = variables;
  17. request.method = URLRequestMethod.POST;
  18. try {
  19. navigateToURL(request, "_self");
  20. } catch (e:Error) {
  21. trace(e);
  22. }
  23. }

Report this snippet 

You need to login to post a comment.