dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS3 FileReference download problem

  1. #1
    Junior Member
    Join Date
    Feb 2005
    Posts
    21

    AS3 FileReference download problem

    Hi,

    Does anyone know how to resolve this or has experienced the same issue?

    I have built an audio player that is xml driven and allows users to select an mp3 file to listen to, then play it. [this bit works]

    I would also like to offer users the option of downloading the track.

    So far I have built a function that that works if users want to download the first track in the xml file [ie the first url from the xml file is passed through to the download button].

    I've also got the url to pass to the download button if a user clicks the next track button, but when I run it, download the first track [which works] then choose a different track then click download I get the code below:

    Error: Error #2041: Only one file browsing session may be performed at a time. at flash.net::FileReference/download()
    at MethodInfo-47()


    I've tried adding a 'file = new FileReference' in the Event.Complete handler but this doesn't work and I can't think what else to try or how to close off the download session...

    Does anyone have any ideas or similar experiences...?

    Thanks in advance!

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Have you used file.cancel(); before starting a new download?
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Feb 2005
    Posts
    21
    Hi. Thanks for that! Unfortunately it doesn't seem to work but I'll have another crack and post an answer if I find one. [any further thoughts welcome]

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Can you show once your code, the part, which is important for the download.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Junior Member
    Join Date
    Feb 2005
    Posts
    21
    Below is the code. The url that is to be downloaded is passed through to the function below either from onload xml function or the next track function.

    I'm thinking the issue might be the filename so am currently testing adding a new line in the xml file that holds the filename to then pass that through as a variable. [at the moment the filename is simply taken from the url as you'll see]

    Thanks!

    function getUrl(urlForDownload):void {
    file = new FileReference;
    var downloadURL:URLRequest = new URLRequest(urlForDownload);

    linkDownload.addEventListener(MouseEvent.CLICK, FileReference_download)
    function FileReference_download(e:MouseEvent) {
    //var fileName:String = "filename.mp3";
    configureListeners(file);
    file.download(downloadURL);
    }
    function configureListeners(dispatcher:IEventDispatcher):vo id {
    dispatcher.addEventListener(Event.CANCEL, cancelHandler);
    dispatcher.addEventListener(Event.COMPLETE, completeHandler);
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    dispatcher.addEventListener(Event.OPEN, openHandler);
    dispatcher.addEventListener(ProgressEvent.PROGRESS , progressHandler);
    dispatcher.addEventListener(SecurityErrorEvent.SEC URITY_ERROR, securityErrorHandler);
    dispatcher.addEventListener(Event.SELECT, selectHandler);
    }
    function cancelHandler(event:Event):void {
    trace("cancelHandler: " + event);
    }
    function completeHandler(event:Event):void {
    trace("completeHandler: " + event);
    downloadText.gotoAndPlay(3);

    }
    function ioErrorHandler(event:IOErrorEvent):void {
    trace("ioErrorHandler: " + event);
    downloadText.text = String("ioErrorHandler");
    }
    function openHandler(event:Event):void {
    trace("openHandler: " + event);
    }
    function progressHandler(event:ProgressEvent):void {
    var file:FileReference = FileReference(event.target);
    downloadText.gotoAndStop(2);
    //trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
    }
    function securityErrorHandler(event:SecurityErrorEvent):voi d {
    trace("securityErrorHandler: " + event);
    downloadText.text = String("Security error");
    }
    function selectHandler(event:Event):void {
    var file:FileReference = FileReference(event.target);
    trace("selectHandler: name=" + file.name + " URL=" + downloadURL.url);
    }
    }

  6. #6
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Try declaring a new file in the button eventhandler function. If you don't use file in other parts make it a local variable. I am not sure why this occurs.

    var file:FileReference = new FileReference;
    configureListeners(file);
    file.download(downloadURL);
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  7. #7
    Junior Member
    Join Date
    Feb 2005
    Posts
    21
    Thanks for looking! I'll give it a try and post the results and hopefully a working solution

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center