01 April 2009

This Editor Fails

Can I ask for a better editor? Is it too much to ask?

It can't paste when you're in Safari, and it can't tab when you're in Firefox. It messes up blockquotes and there is no built in <pre> or <code> buttons.

I suppose I should stop whining and edit the HTML directly... O.o

{Oh and apparently it yells at <pre> tags. <code> tags work though! ^.^}

Adventures in Adobe Flash

Today I was thrown into the world of Flash OOP. I find it rather amusing that I somehow seem to get myself into things without really having much of a background, but nonetheless, I eagerly fall right into it. :D

Anyways so here I am, meandering around in this "mess" of code hopelessly prodding around each corner. Thankfully, most of the grunt work had been done for me. Unfortunately, the programmer before left no comments... -.- Wonderful!* Talk about a trade-off.

*{I suppose that would be a hypocritical statement seeing as my commenting diligence is less than adequate}

Before I go any further, my objective was to get this code sample of a flash file uploader to work with our existing form uploading system. {I say "code sample" because it really wasn't a great piece of work. I mean, it did the job... but a hard-coded POST url?! Really?}

My first task was to figure out a way to post a form full of other variables {i.e. title, description, etc} to another page along with the flash image POST. So far, it's all good. I just pass along the variables as URL vars. Although, this poses a problem because I have to get non-flash variables INTO flash! Now that's just a mess waiting to happen... So I started off with the javascript SetVariable function.

var swiffy = document.getElementById('flashObject');
swiffy.SetVariable('key','value');

Works like a charm... for strings that is. It would have made my life a whole lot easier if I could have just passed in a javascript object! Moving on from that disappointment, I started making my own string -> object parser. Just as I was going to test my masterpiece, Brandon has to come over and ruin my glory. Of course I could have just pre-formatted the string as a URL query string and passed that in. Sadly, I succumbed to simple logic and moved on that way.

Now the next fun part comes in when dynamically updating this flash POST URL from form fields. I ended up creating a function that built a query string from a javascript object.

var mediaVars = {};

function buildMediaVarsURL() {
var returnString = '';
for (var key in mediaVars) {
returnString += '&' + key + '=' + escape(mediaVars[key]);
}
return returnString;
}

Not so hard really. The function buildMediaVarsURL just returns a URL query string starting with an '&'. The fun part is updating the flash var each time a change is made to the form.

function changeAndSetVariable(variable,value) {
var swiffy = document.getElementById("flashObject");

mediaVars[variable] = value;

up.SetVariable("urlArgs", buildMediaVarsURL());
}

was my function. And I put the following on each input element.
onKeyUp="changeAndSetVariable(this.name,this.value)"
Works great! It updates a global flash var named urlArgs each time someone updates a form field you have specified. Once the flash program is ready, it can upload the image to the POST URL with all the vars in the URL. Fun stuff!

Now that I look back on it all, I'm sure I could have been able to include these variables as POST elements along with the image... .:sigh:.

11 April 2008

wha?

sohowdoesthiswork?