Calendar

October 2008
S M T W T F S
« Sep   Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Tag Cloud

Categories

Archives

Recent Posts

Recent Comments


« Announcing FotoBooth (web edition) | Main | SCOOP: Google has made a change to the way it indexes SWFs »

FileReference.browse() Bit Me on the Ass Today

By Rich Tretola | October 17, 2008
5,933 views

Flash Player 10 changed the security settings on the FileReference.browse() method. I remember reading about that, and yet I let an app slip through without being updated and guess what happened?

Correct, when I expected the user to get the file dialog, the application just sat there.

So, for those of you who have no idea what I am talking about, Flash Player 10 put in some new security so that the only way to launch the file system dialog is though direct user interaction. In the application, I was referring to earlier, I was calling FileReference.browse() programatically within the result handler of a Cairngorm command. Don’t let this happen to you, check you code now.

Here is a very simple patch that I put in place that didn’t require reworking the entire application flow.

Wherever you have a FileReference.browse() that is being called programatically and is no longer working in Flash Player 10, simply create an Alert that allows allows the user to interact with the application which complies with the new security.

The sample code below shows a function called nonUserCalledFunction. This is the function that originally had the FileReference.browse() method being called programatically. In the new version, it throws an Alert to the user and then the event listener does the FileReference.browse() and everyone is happy again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import mx.controls.Alert;
import mx.events.CloseEvent;
           
private var fileRef:FileReference;
private function nonUserCalledFunction():void{
    Alert.show("Allow ePage to access my file system","Permissions Required",Alert.OK|Alert.CANCEL,null,handleAlert);
}
   
private function handleAlert(evt:CloseEvent):void {
    if (evt.detail==Alert.OK) {
        fileRef = new FileReference()
        fileRef.browse();
    }
}

I hope you didn’t experience this. If you did, I hope this helps solve your problem.

Topics: Flash Player, Flex, Flex 3 (Moxie) | 9 Comments »

9 Responses to “FileReference.browse() Bit Me on the Ass Today”

  1. ssandy Says:
    October 18th, 2008 at 11:41 am

    I tried filererence.save() in flex3 using the latest build (no Gumbo), and got nothing no errors no nothing, will this work in flex 3?

    Reply to this comment

    Rich Tretola Reply:

    The error will only come into play if you call FileReference.save() programatically. If the user triggers the call though a button click, etc, there will be no problems.

    Reply to this comment

  2. Tim Says:
    November 3rd, 2008 at 9:52 pm

    Another approach that did the trick for me… was using a hidden movie clip (button) and a wrapper method

    ExternalInterface.addCallback(”browseWrapper”, null, browseWrapper); // called from my javascript file

    function browseWrapper(){
    browse_btn.onRelease();
    }

    function browse():Void{
    fileRef.browse();
    }

    browse_btn.onRelease = browse;

    Reply to this comment

    Tim Reply:

    actually that didn’t work…. to many flash installs and uninstalls. Please Remove The Comment.

    Reply to this comment

  3. David Says:
    December 29th, 2008 at 2:44 pm

    At 1:41pm on this cold December 29th, I sweat because both my Flu symptoms are peaking and my FB3 application has failed and I’m going into production on the 10 of January. I’ll return to this page to let you know if this actually works and will allow my application to pass the arguments into the headless .cfm cffile uploader. BRB with a tale of glory or defeat.

    Reply to this comment

  4. dandy Says:
    September 15th, 2009 at 9:08 pm

    How to use this code in Flash CS4 As3.? It gives errors when i put it on top of my as3 code. error regarding the ‘private’ property and ‘import mx.*’ properties.

    Regards

    Reply to this comment

    Rich Tretola Reply:

    You can not use mx. package within Flash as these clsses are part of the Flex framework and are not available within Flash CS4.

    Reply to this comment

  5. David Wall Says:
    September 21st, 2009 at 7:44 am

    Welcome to the space ship. Adobe needs to tighten this up… I have a production application that I had to rewrite into html to get it working properly. The security scopes and stopped working, webservices fail on a random basis constantly, and when a Flash Player update comes out, I have to rework my application to get it to work right. I had high hopes, but if Adobe doesn’t get it together…I’ll have to look somewhere else for a viable programming language.

    Reply to this comment

  6. Rubbernecker’s Review - Week 17 | Learn Flex Says:
    December 12th, 2009 at 9:30 am

    [...] FileReference.browse() Bit Me on the Ass Today (from EverythingFlex) [...]

Comments