hi,
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 avail as i could not find
any other solution for this issue. Enjoy!
cheers,
andre souza
ienliven at gmail dot com
# AFLAX Modifications:
# aflax.as, remeber re-export swf file
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)
return ExternalInterface.call(onLoadEvent, success,
key);
}
}
}
# aflax.js
+AFLAX.LoadVars = function(aflax/*, args*/)
{
var flash = aflax.getFlash();
var loadvars = new AFLAX.FlashObject(aflax, "LoadVars");
loadvars.exposeFunction("load", loadvars);
return loadvars;
}
+AFLAX.FlashObject.prototype.addCallback = function(onLoadEvent)
{
this.flash.aflaxAttachLoadVarsEvents([this.id, onLoadEvent]);
}
# END AFLAX Modifications
# MochiKit Modifications:
# Async.js
+ loadJSONDocFAD: function (url, data) {
if (arguments.length > 1) {
var m = MochiKit.Base;
var qs = m.queryString.apply(null, m.extend(null,
arguments, 1));
if (qs) {
url += "?" + qs;
}
}
var d = new AFLAX.LoadVars(aflax);
d.load(url);
return d;
},
# END MochiKit Modifications
# USE CASE:
# index.php
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title> :: loadJSONDocFAD :: </title>
<script type="text/javascript" src="/lib/AFLAX/aflax.js"></script>
<script type="text/javascript"
src="/lib/MochiKit/MochiKit.js"></script>
<script>
var aflax = new AFLAX("/lib/AFLAX/aflax.swf");
function onLoadHandler(success, res)
{
if(success)
{
var res = evalJSON(res);
if(res.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);
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
-~----------~----~----~----~------~----~------~--~---