Re: Flash and pubsub...
hyakugei <[email protected]>
| Newsgroups | gmane.comp.web.mod-pubsub.devel |
|---|---|
| Message-ID | <[email protected]> |
I wrote a base64 en/decoder for flash for another project, but its under an open license.
http://trapeze.com/r_and_d/as/base64.as
I found a couple of article on the whole JS <-> Flash communication thing here:
http://www.macromedia.com/support/flash/ts/documents/browser_support_matrix.htm
and
http://www.macromedia.com/support/flash/publishexport/scriptingwithflash/index.html
The biggest difficulty is "sending" the data from JS to Flash. I think the easiest way is to use the setProperty function from JS to set a specific property in Flash. Flash has a built in function called "watch", which will preform a callback when a "watched" property changes. So, in this way you could send data from JS to specific Flash property which flash is "watching" for changes.
<flash code>
var testProp = "jos"
this.watch("testProp",alert);
function alert(id, oldval, newval) {
trace(id + ": " + oldval + " > " + newval);
return newval
}
testProp = "sam"; // this will trigger the alert function
stop();
</code>
To send data the other way, you could continue to use the FSCommand or the getURL system, depending on the browser combo...
<JS code>
// setup some var to hold the DOM value/id of the swf movie
movie.SetVariable("/:testProp","new val");
// the "/:testProp" is the 'old' style of targeting properties in flash. I don't know if the new
// dot syntax works or not.
</code>
So, i think that should all be good.
Your previous message with all the examples of the POST contents was _extreamly_ helpful. In fact i think you should add that to the FAQ or documentation someplace, as it makes it very clear what the message's traveling to the server look like.
So, now for the new questions! How are the kn_from paths constructed? In the example you gave, you created a tunnel using the following string (missing the POST/host etc data):
"kn_response_format=flash;" +
"do_method=route;" +
"kn_from=/who/jos/s/24/kn_journal"
Can the client define the kn_from paths? Or does the path get created by the server? I've used this example and gotten it "working" (with several caveats), but i'm not really sure what the "/who/jos/s/24/kn_journal" means...
So, i've built a really basic tool...
http://www.trapeze.com/r_and_d/pubsub/t2.fla
and
http://www.trapeze.com/r_and_d/pubsub/t2.swf
(note - its looking for the server on localhost on port 8008)
...for doing experimentation with the python pubsub.py server. It connects, and can send info. I've yet to get info back, other then notification that i've established a route. I have sent a message to a /what/chat app running in a browser from it, which was pretty cool. The only thing i've changed in the pubsup.py file is:
in SimpleTunnel (ln ~481)
<code>
def encode(self, dict):
"""Same as ev_encode, except including the count and
separators, so it can actually be sent on a tunnel."""
# str = self.ev_encode(dict)
str = self.ev_encode(dict) + chr(0)
return "%d\n%s\n" % (len(str), str)
</code>
so i'm just tacking on an extra null byte (chr(0)) to the string to force flash to fire the onData handler. Not pretty, but it works for this...
So, to reiterate, i can do a do_method=route;kn_from=/who/jos/s/24/kn_journal and get a response from the server.
I can do a do_method=notify;kn_to=/what/chat;kn_payload=hello and get it to show up in a browser running the chat1 app.
Thats it so far, but good to get some progress! Again, the thing that i'm a bit unclear about now, is the paths used in kn_to and kn_from. I also have to dig into the python to figure out where it receives the POST data, so i can try to figure out why it drops the connection ...
Cool!
jos
-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge