...

View Full Version : browse for file window on a flash button



xeno439
08-17-2005, 01:56 PM
Hi everyone, I am looking for a way to attach files to my email forms. Does anyone know the javascript to bring up the browse for file window and how I can put that code on a button in Flash? Thanks so much.

nikkiH
08-17-2005, 03:21 PM
There is no javascript code for that*.
Use a file input for html.
How one does this in Flash, I have no idea. They probably have a file input control...?

*cross-browser javascript. MSIE jscript/hta can.

Edit:
There is no javascript code to just invoke Windows' file browse control. I should have been more specific.

martin_narg
08-17-2005, 05:27 PM
NikkiH - You are right - this can't be done in solely flash - there is no file input form element. But, you can force a hack in IE

This only currently works in IE, but am gonna upgrade with Mozilla compatible code (hopefully) after work.

Should give you some ideas. Here's the JS for those who don't wish to download the zip.



function fileBrowser() {
var _d = document.createElement("div");
with(_d.style) {
visibility = "hidden";
display = "none";
}
var _f = document.createElement("form");
var _i = document.createElement("input");
_i.type = "file";
_i.id = "elFileBrowser";
_i.onchange = function() {
document.getElementById("flashID").SetVariable("path", this.value);
}

_f.appendChild(_i);
_d.appendChild(_f);
document.getElementsByTagName("body")[0].appendChild(_d);

if(typeof document.getElementById("elFileBrowser").click() == "undefined") {
// do stuff for gecko DOM
} else {
document.getElementById("elFileBrowser").click();
}
}


If anyone knows how to force the click in Gecko, then please feel free to post up =)

m_n

nikkiH
08-17-2005, 07:40 PM
So you're creating a file input, then invoking its click event...
For Gecko, look at createEvent, initEvent, and dispatchEvent.

Lawn Gnome
08-18-2005, 06:41 AM
hey how do i make the thing send it to me??? :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum