Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    browse for file window on a flash button

    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.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.
    Last edited by nikkiH; 08-17-2005 at 06:42 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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.

    Code:
    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
    Attached Files Attached Files
    Last edited by martin_narg; 08-17-2005 at 04:30 PM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    So you're creating a file input, then invoking its click event...
    For Gecko, look at createEvent, initEvent, and dispatchEvent.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Jul 2005
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey how do i make the thing send it to me???


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •