sorry about the mess.... got sendAndLoad running.
now is possible to send data over POST requests.
follow above:


MochiKit + AFLAX: loadJSONDocFAD

hello, world!

i have done some modification on AFLAX and MochiKit in
order to be able to do loadJSONDoc requests from another
domain using AFLAX proxy with SWF LoadVars object.

this works great for me. so i made it available as
i could not find any other solution for this issue.

Enjoy!

andre souza
ienliven  at gmail dot com



Modifications:


/* MochiKit: Async.js */
+    loadJSONDocFAD: function (url, data, method) {
+        var d = new AFLAX.LoadVars(aflax, data);
+        d.sendAndLoad(url, method);
+        return d;
+    },

MochiKit.Async.EXPORT = [
...
+    "loadJSONDocFAD",
...
];



/* AFLAX: aflax.as */
function aflaxInit():Void
{
...
+       ExternalInterface.addCallback("aflaxAttachLoadVarsEvents", _root,
aflaxAttachLoadVarsEvents);
...
}

+function aflaxAttachLoadVarsEvents(args)
+{
+       var objName = args[0];
+       var onLoadEvent = args[1];
+
+       var obj:LoadVars = objectCache[objName];
+
+       if(onLoadEvent != null)
+       {
+               obj.onLoad = function(success:Boolean)
+               {
+                   for(key in obj)
+                       if(key != 'onLoad' && key != 'origSendAndLoad')
+                           return ExternalInterface.call(onLoadEvent, success,
key);
+               }
+       }
+}



/* AFLAX: aflax.fla */
/* the SWF file must be exported with Network Sandbox.
   that can be seted on Publish Setting on Flash. */
+LoadVars.prototype.origSendAndLoad = LoadVars.prototype.sendAndLoad;
+LoadVars.prototype.sendAndLoad = function(url, method){
+               return this.origSendAndLoad(url, this, method);
+}
#include "aflax.as"



/* AFLAX: aflax.js */
+AFLAX.LoadVars = function(aflax, args)
+{
+       var flash = aflax.getFlash();
+       var loadvars = new AFLAX.FlashObject(aflax, "LoadVars");
+
+       loadvars.exposeFunction("send", loadvars);
+       loadvars.exposeFunction("load", loadvars);
+       loadvars.exposeFunction("sendAndLoad", loadvars);
+
+       for( key in args )
+       {
+           if(key != "______array")
+           {
+               loadvars.exposeProperty(key, loadvars);
+               var cap = key[0].toUpperCase() + key.substr(1);
+               eval("loadvars.set"+cap+"('"+args[key]+"');");
+           }
+       }
+       return loadvars;
+}
+
+AFLAX.FlashObject.prototype.addCallback = function(onLoadEvent)
+{
+       this.flash.aflaxAttachLoadVarsEvents([this.id, onLoadEvent]);
+}



/* USE CASE */
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title> :: loadJSONDocFAD :: </title>

<script type="text/javascript"
src="http://www.domain.com/lib/AFLAX/aflax.js";></script>
<script type="text/javascript"
src="http://www.domain.com/lib/MochiKit/MochiKit.js";></script>

<script>
        var aflax = new AFLAX("http://www.domain.com/lib/AFLAX/aflax.swf";);

        function onLoadHandler(success, res)
        {
                if(success)
                {
                        var parsed = evalJSON(res);
                        if(parsed.state == '1')
                        {
                                console.debug('Login successfull.');
                        }
                        else console.debug("Login FAILED.")
                }
                else console.debug("Connection to server failed.");
        }

        function login()
        {
                var data = {};
                data.username = $("username").value;
                data.passwd = $("passwd").value;
                data.json = 1;

                url = "http://www.anotherdomain.com/index.php";;

                var d = new loadJSONDocFAD(url, data, "POST");
                d.addCallback("onLoadHandler");
        }
</script>
</head>
<body style="background: #eeeeee;">
        <div id="body">
                <input type="text" name="username" value="" id="username" />
                <input type="password" name="passwd" value="" id="passwd" />
                <input type="button" name="Entrar" value="" id="Entrar"
onClick="login()" />
        </div>
        <script>
                aflax.insertFlash(1,1, '#FFFFFF');
        </script>
</body>
</html>


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to