FlashHelper.onload = startApp;

function startApp(fs) {
    if (!fs) { alert("Flash not loaded"); return; }
    fs.Debug();
}

function displayResponse() {
    var response = FlashHelper.getFlash().GetVariable("retText");
    $("response").value = response;
}

function makeCall() {
    var url = $("url").value;
    var method = $("method").value;
    var body = $("body").value;
    var contentType = $("contentType").value;
    
    var fs = FlashHelper.getFlash();
    //fs.loadPolicyFile("http://domain/blah/crossdomain.xml");
    fs.XmlHttp(url, "displayResponse", method, body, contentType);

    $("response").value = "loading...";
    //$("response").innerHTML = url + " " + method + " " + body + " " + contentType;
}

function makeCall2() {
    var url = $("url").value;
    var method = $("method").value;
    var body = $("body").value;
    var contentType = $("contentType").value;

    $("response").value = "loading...";

    var xhr = new FlashXMLHttpRequest();
    xhr.onload = function() { $("response").value = xhr.responseText; }
    xhr.open(method, url);
    
    // note: Content-Type is a special header
    xhr.setRequestHeader("Content-Type", contentType);
    
    // note: other headers only work with POST, not GET
    xhr.setRequestHeader("Authorization", "test");
    xhr.setRequestHeader("x-amz-acl", "public-read");
    xhr.setRequestHeader("content-md5", "hello");
    //xhr.setRequestHeader("content-length", 33); 
    xhr.setRequestHeader("Date", "today");

    xhr.send(body);
}
