Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is it possible to trigger for example flash uploading button via javascript?

For example I have made empty image wrappers and by clicking on them, they trigger flash button to open as select window.

Thanks!

share|improve this question
add comment (requires an account with 50 reputation)

3 Answers

up vote 4 down vote accepted

Assuming you have a flash function in your SWF, like this:

// AS3 code in swf
function myfunction():void
{
    // Do something useful
}

You can expose it to JavaScript in a page that contains your SWF like this:

// AS3 code in swf
ExternalInterface.addCallback("myfunction", myfunction);

Then from JavaScript you can call it like this:

// JavaScript code in browser
var swf = window.getElementById("myswf");
swf.myfunction();

In your case you can invoke the code you want to run from myfunction().

share|improve this answer
Thanks i'll look into it. – Somebody Apr 16 '10 at 15:32
add comment (requires an account with 50 reputation)

Although the ExternalInterface makes it possible to call ActionScript functions from JavaScript, I don't think it will work for opening a file browser and uploading files.

For security reasons, the file upload functions in Flash Player can only be triggered by user interaction, like clicking a button, in Flash. This was introduced with Flash Player 10, and broke a lot of file upload solutions, like SWFUpload and others:

http://www.bit-101.com/blog/?p=1382

share|improve this answer
add comment (requires an account with 50 reputation)

Yes, through the ExternalInterface class.

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.