File IO in Flex

Were thinking about using Flex at work to create a user
interface for an application. One of the things we are going to
need to do is create a .txt file with some data that can be read by
a different app. Looking thru the documention I don't see a way to
do that in Flex. Is there a way to a simple text file write to the
client machine?
Thanks

Shouldn't be hard to do - take a look at Class FileStream in
the API docs. I think it has an example there too. =) (Could be
mistaken)
http://livedocs.adobe.com/apollo/1.0/aslr/flash/filesystem/FileStream.html
Edit: Ahh, wait a sec - I forgot I'm in the FLEX forum and
not the AIR forums. I don't think you can do that with a standard
Flex app, for security reasons. You'd need to use AIR.
Edit 2: But I'd imagine you'd still be able to get the user
to do a standard file download through the browser, although I'm
not sure and I've never tried that.

Similar Messages

  • How can i Upload Files from my Flex 2.0 Application?

    How can i do a Upload File funtionality with Flex 2.0? Do i
    have to make the component? How is the code in Flex/ Action Script
    to make this possible?. I'm new in this Flex world and it seems to
    me very interesting to make RIA's Applications; in fact i'm making
    a little Employees Application for my company and i'm trying this
    technology and of course i need the functionality that i asking
    for.
    Regards.
    Andres.

    I haven't tried this, but I believe what you could do is
    append
    requestHeaders to the urlrequest object that you pass into
    the file.upload()
    method. The requestHeaders is an array of name/value pairs
    that would be
    included with your post. At least in theory, I believe that
    shoudl work.
    Good luck.
    Phil
    "tantalo" <[email protected]> wrote in
    message
    news:e3q3mt$138$[email protected]..
    > Hi. Phil, how i commented in the forum the examples
    works ok, with a
    > little
    > changes to make a file Upload. Now i have another doubt,
    i need to make a
    > submit of a form with another fields and the file
    selected.
    >
    > I made a HHTP Service for that purpose with the tags
    Requests like:
    >
    > <mx:HTTPService id="empleadoRequest"
    > url="
    http://andresbarrios:8080/directorio/empleados/insertarEmpleado.jsp"
    > useProxy="false" method="POST">
    > <mx:request xmlns="">
    >
    <empresa>{empresa.selectedItem.data}</empresa>
    >
    <ubicacion>{ubicacion.selectedItem.data}</ubicacion>
    >
    <departamento>{departamento.selectedItem.data}</departamento>
    > <cedula>{cedula.text}</cedula>
    > <nombre>{nombre.text}</nombre>
    > <apellido>{apellido.text}</apellido>
    > <!--Falta Fecha de Nacimiento -->
    > <sexo>{sexo.selectedItem.data}</sexo>
    >
    <estado_civil>{estado_civil.selectedItem.data}</estado_civil>
    >
    <telefono_celular>{telefono_celular.text}</telefono_celular>
    > <extension>{extension.text}</extension>
    >
    <correo_electronico>{correo_electronico.text}</correo_electronico>
    > </mx:request>
    > </mx:HTTPService>
    > I have the global variable called "file" that contains
    the file selected.
    > I
    > want to send this file variable in the HHTPservice call
    EmpleadoRequest,
    > can i
    > do that with a Request tag like another field? or the
    only way is trougth:
    > file.upload(upload.cfm) ?;
    >
    > I want only make a one call to the server to submit the
    fields of the form
    > and
    > to upload the file at th e same time can you help me How
    can i do that?
    >
    > Thanks.
    >
    > Regards.
    >
    > Andres.
    >
    >
    >

  • Access file object from flex web app

    Hi all,
    I want to access file object from flex web app. What should i do?
    I have to take array from my XML. In XML there will be only dir path. So for taking file name from dir i have to access it and have to perform for loop on that dir.
    What should I do?
    Any Ideas?
    Thanks,
    -CK

    Hi Michael
    My question is that I dont want to give name of images in XML file.
    In XML file there will be only path of image directory. So I need to find all image name from that image directory.
    Thats why I want to access file object.
    Any ideas?    

  • How to insert a swf file in to flex..

                   hi all
    i'm trying to insert a swf file in my flex. I'm trying to insert a help manual e-book to my flex application,
    i dont have any idea in flex... i have some 1 month experiance in flex...
    so plzzz help me...

    Are you just looking to load an external swf into your flex application? Are there any requirements where the external swf has to be stored like on a different domain or can it be packaged with your Flex app?

  • File Upload using Flex/ColdFusion.  2044 error

    I am looking for a little more clarity around the file upload using Flex and Cold Fusion.  When I run this using my server I get Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
    I did create a regular cfform and had it use my ColdFusion upload form and that worked fine, so I feel good about the upload form. I am starting to think there is a permission error with the Flash Player writing to the folder.  When this is ran, it will show the file being 100% loaded but the complete event is never triggered.  I put alerts to see where it hits and 100 does show at the same time as my error message.  The complete alert never shows.  I also put an alert in my cfm page and it never reaches that page to hit it.  Whether I use an absolute URL or relative path. I have also tried the urlrequestmethod.post and nothing changed.  Thanks in advance.  BTW.  I am using Flex 3.
    This is my mxml file
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:example="com.example.*" horizontalAlign="center" viewSourceURL="srcview/index.html">
    <mx:Script>
    <![CDATA[
    import com.example.FileDownload 
    import mx.controls.Label 
    import com.example.FileUpload]]>
    </mx:Script>
    <mx:Label id="title" text="File I/O Example" fontSize="24" fontStyle="bold" />
    <mx:Text id="subtitle" text="From Programming ActionScript 3.0, Chapter 22: Networking and communication" width="100%" textAlign="center" fontSize="12" /><example:FileDownload 
    id="fileDownload" creationComplete="fileDownload.init(downloadProgress, cancelDownload);" />
    <example:FileUpload id="fileUpload" creationComplete="fileUpload.init(uploadProgress, cancelUpload);" />
    <mx:HBox>
    <mx:Panel title="Upload File" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
    <mx:ProgressBar id="uploadProgress" label="" mode="manual" />
    <mx:ControlBar horizontalAlign="right">
    <mx:Button id="startUpload" label="Upload..." click="fileUpload.startUpload();" />
    <mx:Button id="cancelUpload" label="Cancel" click="fileUpload.cancelUpload();" enabled="false" />
    </mx:ControlBar>
    </mx:Panel>
    <mx:Panel title="Download File" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
    <mx:ProgressBar id="downloadProgress" label="" mode="manual" />
    <mx:ControlBar horizontalAlign="right">
    <mx:Button id="startDownload" label="Download..." click="fileDownload.startDownload();" />
    <mx:Button id="cancelDownload" label="Cancel" click="fileDownload.cancelDownload();" enabled="false" />
    </mx:ControlBar>
    </mx:Panel>
    </mx:HBox></mx:Application>
    here is my coldfusion upload script
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <script>alert('hello')</script>
    <cfset currentPath = getCurrentTemplatePath()>
    <cfset currentDirectory = getDirectoryFromPath(currentPath)>
    <cfoutput>This directory is #currentDirectory#</cfoutput>
    <cffile action="UPLOAD" filefield="Filefield" destination="#currentDirectory#" nameconflict="OVERWRITE"/>
    </body>
    </html>
    here is the package
    package  
    com.example { import flash.events.*; 
    import flash.net.FileReference; 
    import flash.net.URLRequest; 
    import flash.net.URLRequestMethod; 
    import mx.controls.Button; 
    import mx.controls.ProgressBar; 
    import mx.core.UIComponent; 
    import mx.controls.Alert; 
    public class FileUpload extends UIComponent { 
    // Hard-code the URL of the remote upload script. 
    private const UPLOAD_URL:String = "upload_script.cfm"; 
    private var fr:FileReference; 
    // Define reference to the upload ProgressBar component. 
    private var pb:ProgressBar; 
    // Define reference to the "Cancel" button which will immediately stop the upload in progress. 
    private var btn:Button; 
    public function FileUpload() {}
    /*** Set references to the components, and add listeners for the SELECT,
    * OPEN, PROGRESS, and COMPLETE events.
     public function init(pb:ProgressBar, btn:Button):void { 
    // Set up the references to the progress bar and cancel button, which are passed from the calling script. 
    this.pb = pb; 
    this.btn = btn; 
    fr =
    new FileReference();fr.addEventListener(Event.SELECT, selectHandler);
    fr.addEventListener(Event.OPEN, openHandler);
    fr.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    // fr.addEventListener(Event.COMPLETE, completeHandler); 
    /*** Immediately cancel the upload in progress and disable the cancel button.
     public function cancelUpload():void {fr.cancel();
    pb.label =
    "UPLOAD CANCELLED";btn.enabled =
    false;}
    /*** Launch the browse dialog box which allows the user to select a file to upload to the server.
     public function startUpload():void {fr.browse();
    /*** Begin uploading the file specified in the UPLOAD_URL constant.
     private function selectHandler(event:Event):void { 
    var request:URLRequest = new URLRequest(UPLOAD_URL); 
    /* request.url = UPLOAD_URL*/request.method = URLRequestMethod.POST;
     try  
    {fr.upload(request);
    }catch (error:Error){
    trace  
    ("error uploading")}
     /*** When the OPEN event has dispatched, change the progress bar's label
    * and enable the "Cancel" button, which allows the user to abort the
    * upload operation.
     private function openHandler(event:Event):void {pb.label =
    "UPLOADING";btn.enabled =
    true;}
    /*** While the file is uploading, update the progress bar's status and label.
     private function progressHandler(event:ProgressEvent):void {pb.label =
    "UPLOADING %3%%";pb.setProgress(event.bytesLoaded, event.bytesTotal);
    if(event.bytesLoaded==event.bytesTotal){ 
    trace(Event.COMPLETE)Alert.show(
    "100")}
    /*** Once the upload has completed, change the progress bar's label and
    * disable the "Cancel" button since the upload is already completed.
     private function completeHandler(event:Event):void {Alert.show(
    "in function")pb.label =
    "UPLOADING COMPLETE";pb.setProgress(0, 100);
    btn.enabled =
    false;}

    Presumably you need to add a result handler to your request.

  • File Chooser in Flex

    I want to make a file chooser that can allow me to choose
    (Browse) where's the file that i want to upload. Anyone know how to
    create a file chooser with flex builder 2 ? I'm very appreciate for
    any answer.

    Here is an example that will make a file browser to choose
    either an image or mp3 file:
    private var upload_ref:FileReference;
    private function upload_media():void {
    var media_filter:FileFilter;
    var filter_array:Array = new Array();
    media_filter = new FileFilter("Images (*.jpg, *.jpeg, *.gif,
    *.png)", "*.jpg; *.jpeg; *.gif; *.png");
    filter_array.push(media_filter);
    media_filter = new FileFilter("Audio (*.mp3)", "*.mp3");
    filter_array.push(media_filter);
    upload_ref = new FileReference();
    upload_ref.browse(filter_array);
    upload_ref.addEventListener(Event.SELECT, file_selected);
    private function file_selected(evt:Event):void {
    if (upload_ref.name != null &&
    upload_ref.name.search(" ") == -1 &&
    upload_ref.name.search("'") == -1) {
    var sendVars:URLVariables = new URLVariables();
    sendVars.file_path = "/path_on_server_to_upload_to";
    var request:URLRequest = new URLRequest();
    request.url = "
    http://yourserver.com/upload_php_script.php";
    request.data = sendVars;
    request.method = URLRequestMethod.POST;
    upload_ref.addEventListener(Event.COMPLETE, completeUpload);
    upload_ref.upload(request);
    } else {
    Alert.show("File name can only include letters, numbers or
    underbars. No spaces.");
    Vygo

  • File uploads from Flex

    How do I enable CF to allow file uploads from Flex?

    You will need to set the accept attribute of the cffile tag
    to allow the mime type application/octet-stream.

  • Set file filters in flex for save, not for browse

    How can i set file filters in flex for save, not for browse?
    Right now i am using filereferce class for saving purpose but i could
    not able to set filter. We can easily do it for browse.

    You can try to delete [http://kb.mozillazine.org/mimeTypes.rdf mimeTypes.rdf] in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder]
    * http://kb.mozillazine.org/File_types_and_download_actions#Resetting_download_actions
    Create a new profile as a test to check if your current profile is causing the problems.
    See:
    * [https://support.mozilla.com/kb/Basic+Troubleshooting#w_8-make-a-new-profile Basic Troubleshooting: Make a new profile]
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins" in case there are still problems.
    If that new profile works then you can transfer some files from the old profile to that new profile (be careful not to copy corrupted files)
    See:
    * http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • How to load and display a byte array (jpeg) image file dynamically in Flex?

    My web service client (servlet) received a binary jpeg data from an Image Server. The Flex application invokes the
    servlet via HttpService and receives the binary jpeg data as byte array.  How could it be displayed dynamically
    without writing the byte array to a jpeg file?  Please help (some sample code is very much appreciated).

    JPEGEncoder is only useful for converting BitmapData to ByteArray, not the other way around.
    By the way JPEGEncoder and PNGEncoder are part of the Flex SDK now, so no need to use AS3Lib (alltough it's a good library to have around).
    To display/use a ByteArray as image, use a Loader instance with the loadBytes method.
        Loader.loadBytes(bytes:ByteArray, context:LoaderContext = null);
    Listen for the complete event on the Loader.contentLoaderInfo and get the BitmapData in the event handler.
    private function loadJpeg():void {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
        //jpgBA is the ByteArray loaded from webservice
        loader.loadBytes(jpgBA);
    private function loaderCompleteHandler(evt:Event):void {
        var t:LoaderInfo = evt.currentTarget as LoaderInfo;
        // display the jpeg in an Image component
        img.source = t.content;
    <mx:Image id="img" scaleContent="false" />

  • Issues with file upload in flex mobile application (sharepoint as backend)

    Hello,
    I am working on flex mobile application for android platform for which we are having sharepoint as a backend.
    (Flex SDK 4.6 and AIR 3.9)
    Issue which we are facing is as follows:
    We are communicating with the backend server using webservices: example:
    <s:WebService id="kWebService" wsdl="http://www.kservice.net/kdatabaseservice.asmx?WSDL" >
                <s:operation name="AddPost"
                             resultFormat="object"
                             result="addPostResult(event)"
                             fault="postsfaulterr(event)" />
    </s:WebService>
    Above services are working fine but we are facing issue with one service which is related to file upload.
    File upload for <10 MB is working fine but when we try to upload larger file on server it fails to process.
    We are sending bytearray to the backend and backend code is writing those bytearray into file.
    We have tried many ways to overcome from this situation. like we have checked configuration for file upload size on server , we have tried wcf services as well. Please help us on this criticle point as soon as possible
    Thanks
    Dhwani

    Prashant8809 wrote:
    Hi
    >
    > I have already gone through the video by Thomas Jung for multiple file upload but it saves the contents in server and not in >transparent table. So please suggest me alternative solutions.
    >
    >
    > Regards
    > Prashant Chauhan
    What do you mean that my video saves the contents int he server and not in transparent table?  I save the data into a temporary database table so it can be accessed by the parent WDA session. From there the WDA session can do whatever it wants with it.  What do you mean by transparent table - that would be a database table. Do you actually mean internal table?  if so, just read the data from the temporary database table into memory.

  • Setting file extension for flex download

    Hi, I have a flex/flash download app that I use on my website, but a lot of people have trouble with it because they rename the file and accidentally remove the .zip from the end of the file name.  Is there any way that i can prevent this?  I have noticed that when i click to download, the "Save as Type" drop down is blank.  It looks like this:
    File name: myFileName.zip
    Save as type:
    I'm hoping that im just missing a param that i can set to .zip so that it will look more like this:
    File name: myFileName
    Save as type: .zip
    Thanks!

    Hi,
    You can restrict them to save in any other format by making the check.
    Simply add listner for the Event.OPEN on the fileReference and inside this check for your allowed extension,if the extension is not what you want then
    simply right a line there like:-
    fileReference.cancel();
    And addtionally you can give any alert that your file should be of that particular extension.
    with Regards,
    Shardul

  • File Filter on Flex Uploader

    Hi,
    I would just like to ask for some help regarding my flex
    uploader. My problem is I can't filter the file types when i am
    uploading. For example I only wanted to see image files (.jpg,
    .png, .gif) when browsing files to upload but instead I always get
    All file types. Here's my code just in case you need it.
    thanks a lot. any feedback would be very much appreciated.

    I'm thinking you can file the following under "obvious", so
    excuse if it is...
    if you only want to see the image file types you mentioned,
    you'd have to remove the other file types (*.swf, *.bmp) passed to
    the FileFilter constructor. Also, you want to pass an Array to the
    browse() function, so use the following in your addFiles()
    function:
    _refAddFiles.browse(filesToFilter);
    and not
    _refAddFiles.browse(imageTypes);
    On Windows you'll get only the file types listed in the
    dialog box and on a Mac you'll see all files, but only the file
    types listed will be selectable, the others are grayed out. Don't
    know what it looks like on Linux.
    TS

  • How to use an SWF file generated by Flex as a Stand Alone file

    Whenever we compile an MXML file, there is an SWF file
    generated. This file is not a standalone file and will not work on
    any other computer expect on the computer where there is a Project
    file created by the Flex builder.
    Why am I not able to use that SWF file as a stand alone file?
    If I want to use that SWF file alone as in the SWF generated
    by Flash what do I have to do?
    Regards,
    Rashmi

    The swf file will run from anywhere. What's it doing when you
    try to open it on another machine?
    The only thing I can think of is if you're getting a security
    violation in which case you would need to read about Flash Player
    trust files and security.
    -Mac

  • File system in flex

    Hi experts,
                 I have one folder it contains number of files(.txt file or .swf or ny thing).I have  to show all the files in datagrid.I have no idea about this, is it possible to read a folder in flex.
    This is urgent requirement plz help me

    In Flex, it would be possible only if you'd find a way to read your local file system with a server-side script and pass the read data to Flex where you can rebuild the exact structure and do something with it ( not sure what ). As for AIR, you have a FileSystemDataGrid that does exactly what you are looking for ( just that it's "AIR only" ).

  • Flex files in Non-Flex Project

    I use Eclipse for developing in Java. I have been trying out
    the Flex 3 (public beta) plugin for Eclipse. I can create a new
    Flex project and all of the Flex files compile and work correctly.
    But how do I add Flex files to an existing project (non Flex
    project) I already have created and setup it up so the Flex files
    (.mxml, etc..) will be compiled and built correctly.
    Thank you

    Hey there,
    I tried install a debug version of flash as you suggested. I
    got this error from Firefox:
    But I can't understand why this error could be happening
    because the program works perfectly in IE.
    TypeError: Error #1010: A term is undefined and has no
    properties.
    at FlexAnnotationProject/annotationsLoaded()
    at FlexAnnotationProject/loadAnnotationEvent()
    at FlexAnnotationProject/__loadAnnotation_result()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.rpc.http.mxml::HTTPService/
    http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
    at mx.rpc::AbstractInvoker/
    http://www.adobe.com/2006/flex/mx/internal::resultHandler()
    at mx.rpc::Responder/result()
    at mx.rpc::AsyncRequest/acknowledge()
    at ::DirectHTTPMessageResponder/completeHandler()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()
    Any ideas?
    Aaron

Maybe you are looking for

  • PL/Sql concurent program in Oracle 10.7

    Hi I am creating a PL/SQL concurrent program in Oracle version 10.7. I need to write some messages to the log file. I know this can easily be done in 11i using FND_FILE. In 10.7, I am trying to use UTL_FILE. I get the logfile name from FND_CONCURRENT

  • Need An SQL Query

    Hello, Kindly have a look at two tables… Item_Master Item_Code Item_Name     1          ParentA     2          ChildA          3          ChildB          4          ChildC          5          ParentB     BOM_Relation Parent_ID Child_ID Quantity 1    

  • Question about Technologies in JAVA

    Hi all, I'm starting my final project for Computer Science in University and I pretend to develop an integrated e-learning environment for my faculty. I want to develop this by using JAVA WEB START within a JNLP, as a stand-alone application (not wit

  • Satellite L850 - What are these strange programs?

    Here is a picture of two unknown programs that appear on my PC: http://img29.imageshack.us/img29/2065/sinttulofvb.jpg Please, help me. I think they are virus. How can I know what are them and remove them? Thank you.

  • Siri doesn't understand stars in music and playlists

    I love the idea of using Siri to control music playlist, but she doesn't seem to understand stars.  For example, I have a smart playlist called "★★★★", and when I ask her to "play playlist 'four stars'" she instead tries to play a song or album with