Luc
Luc

Reputation: 2805

Adobe Flash and JSON

I'm a newbie in adobe flash development.

I have form login, and I want to login with my api, which like this: /api/login and with user & pass.

And I don't know how to.

Which I have?

  1. IDE: Adobe Flash Professional CS6
  2. The form with username & password field

What I need?

  1. How to connect to API and get response
  2. How to send request to server with POST & GET

Thanks so much!

Upvotes: 2

Views: 403

Answers (1)

Creative Magic
Creative Magic

Reputation: 3151

You can send GET/POST request with the URLLoader class:

import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;

var urlRequest:URLRequest = new URLRequest("LINK_HERE");
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = your_json_object;

var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.load(urlRequest);

function onComplete(e:Event):void
{
    trace(e.currentTarget.data); // the response from the server
}

Upvotes: 1

Related Questions