First, a confession. I was kind of a dick to Mike Chambers about his and Christian Cantrell’s Flash JavaScript Integration Kit last week. To me, I find the whole use of Flash and JavaScript talking is ridicolous in terms of using it for AJAX like functionality; Flash has asyncronous XML and so does JavaScript; why mix the two?
Additionally, the only project I ever had in the past that required Flash talk to JavaScript was kind of stupid anyway; I had Flash controlling Windows Media Player videos since the content was already in a million dollar content management system, and Flash video was out of the question (meaning I couldn’t sell them on it). So, although I managed to get it to work with fscommand’s to JavaScript (since using getURL to control volume of a WMV file through JavaScript didn’t work because getURL was refreshing the page), I still thought it was stupid, and the only point of every using JavaScript and Flash was if you needed to hack some functionality in.
…of course, I got paid good money on the project, money which I 2 years later quickly passed back to the IRS (wtf?). Regardless, it was a project I did, and needed functionality for and successfully implemented. Would it have been better to have MC’s(get it?) integration kit back then? Yep; switch statements with fscommand and watches on _root blow when dealing with AS2 and trying to be OOP.
We have a need for Fileupload in our current project. Remembering my pains of the past, I quickly downloaded their kit to see if it’d integrate into our workflow better, and low and behold yes. I can’t get it to work in an ARP command (I think because commands are local variables, kept around only by the activation object, and this is causing issues…?), but it works great in our main class.
So, since Yamago’s YamzBrowser is AS1 and uber-haxorish with FlashVars initing SWF’s, I’d rather just use the necessary JavaScript to let JSP tell us what’s up, and either JavaScript back, or LocalConnection back; works on another project, so cool, we’re just making the JavaScript and Flash cleaner this project.
This is the 2nd project in my lifetime that’s required hardcore JavaScript and Flash interaction; and I’m getting paid for both… that kind of solidifies the need for what Mike & Christian created and confirms it’s validity… oops, I’m an idiot, and my technology bigotry comes through loud and clear. Sorry guys, I was wrong.
One problem, though, is the Wiki docs currently have the FlashTag write to the document. This ends up replacing your current webpage with the Flash embedding. Since my team is mainly Flash, we managed to figure out a better way (which to a web-head, I’m sure there’s an even better way, but this way works pimp).
We load the Flash into a div tag instead, which I’ve done many times in the past to better control positioning and styles. So, while the Wiki (currently) says this:
<script type="text/javascript">
// The arguments below are path, width, height, and Flash Player version.
var tag = new FlashTag('/path/to/flashContent.swf', 300, 300, '7,0,14,0');
tag.addFlashVar('lcId', uid);
tag.write(document);
</script>
To put it in a div tag instead, we did:
<script type="text/javascript">
var tag = new FlashTag('/path/to/flashContent.swf', 300, 300, '7,0,14,0');
tag.addFlashVar('lcId', uid);
myDiv = document.getElementById("flash_div");
myDiv.innerHTML = tag.toString();
</script>
And the div looks like:
<div id="flash_div" style="width: 600px; height: 600px;"></div>
It works damn good; thanks guys!