Daniel Dura

All About the Adobe Flash Platform

Can Teens Take ViagraOverseas ViagraDiscount Skocz.pl ViagraGeneric Viagra SafeCheap Viagra 50mgCan I Take ViagraGeneric Viagra Free ShippingFemale Herbal ViagraFemale Version Of ViagraBuying Viagra OnlineViagra Best BuyBuy Cialis Online ViagraVipps PharmacyZip ViagraHerbal Viagra EquivalentHistory Of ViagraSafe For Females To Use ViagraViagra Prescription DrugViagra PillZocor Alternative ViagraBuy Cialis ViagraViagra PharmacyMexico Pharmacy Generic ViagraViagra ProblemsViagra StoresViagra DosageCheap Onlinecom Order ViagraDiscount Priced ViagraViagra Affect A FemaleGuaranteed Cheapest ViagraHerbal ViagraViagra Online OrderingViagra Prescription UkBuy Cheap Viagra Online UkAlternative Female ViagraViagra ScotlandViagra Pay After DeliveryCitrate Salt Of SildenafilBuy Viagra Now OnlineViagra For RecreationViagra Studies WomenCheapest Sildenafil CitrateCheap Viagra UkWholesale ViagraViagra For Sale In GibralterCialis Levitra Viagra VsGeneric Ogden ViagraSelling ViagraDoes Herbal Viagra Really WorkCheap Cialis Levitracom ViagraWho Can Take ViagraViagra Alternative UkViagra Purchase By PhoneImitation ViagraViagra Side EffectsViagra JokesLegally Purchase ViagraWomen Does Viagra WorkViagra Without PrescriptionViagra FastAdvice ViagraBuy Viagra In EnglandKoluba.up2.co.il Order ViagraViagra By OnlineFree Sample Offers In CanadaViagra Collection ServiceCheapest Generic ViagraCheap Generic Overnight ViagraViagra PrematureSildenafil Citrate 50mgFemale Ingestion ViagraViagra Sale OnlineViagra FaqCheap Less ViagraViagra Next Day DeliveryIs Vigrx Available In StoresWhat Is Viagra Used ForViagra 50 Mg TabletsPerformance Anxiety ViagraDangers Of ViagraViagra With No PrescriptionBrand Drug Generic Name ViagraFree Consultation ViagraBest Prices On ViagraBuy Real Viagra OnlineCialis Levitra Viagra Vs VsPc100 ViagraFree Viagra SampleHow To Make Your Own ViagraWho Should Not Take ViagraAlternate Uses For ViagraBuy Viagra On LineFree ViagraCheapest Viagra In The WorldViagra PlantOral ViagraHow Much Does Viagra CostPicture Viagra PillViagra ResultsViagra Soft GenericViagra Pill For WomenGeneric Pack ViagraViagra How It WorksCheap Pill ViagraViagra InstructionsVgx-viagraCan Young Men Take ViagraAlternative Search ViagraPurchase Sildenafil CitrateViagra Discussion BoardCheap Robert.up2.co.il ViagraGel Tab ViagraViagra Alternative MerckFemale Ingestion Of ViagraViagra Cialis CheapViagra BritainGeneric Viagra In UkViagra Buy ViagraIs Viagra LegalOnline Order Url ViagraSwiss Oats A111Viagra For TeensViagra Online UkAlternative Viagra DrugBuy Viagra PillViagra Female U KBest Price ViagraLowest Viagra PriceBuy Levitra Online ViagraHerbal VigorDiscount Phentermine ViagraMake Your Own ViagraViagra CreamBest Natural ViagraCheap ViagraBook Buy Guest Sign ViagraViagra UsageBuy Inurl Viagra ViagraGeneric Viagra Blue Pill 25mgAdverse Side Effects Of ViagraViagra Alternative And WomanFemale Viagra CreamViagra CartoonsLink Online Suggest ViagraViagra For WomanViagra Benefits Side EffectsDrug Sample ViagraViagra GenericDoes Viagra ExpireViagra Uk PurchaseCream Female Viagra VigorelleBuy Cheap Viagra In UkViagra PatentViagra Online KaufenFemale Version ViagraOver The Counter ViagraViagra Pill SplitterViagra TabletsViagra In MexicoBuy Online Pharmacy ViagraGeneric Viagra OnlineIndian Sildenafil CitrateAge Of Viagra UsersSildenafil Citrate VoltammetryOrder Viagra On LineViagra Online StoreBuy Generic ViagraBuy Viagra InternetBuying Generic CialisAlternate To ViagraViagra And LisinoprilResearch On ViagraViagra The Little Blue PillBuy Viagra WomanViagra ReviewsNo Prescription ViagraViagra Vs CialisWhat If I Take Too Much ViagraCheapest Online ViagraViagra Mail Order UkNatural ViagraHow Does Viagra WorkGet Viagra Avoid PrescriptionViagra ForumsViagra Cialis LevitraViagra Price ComparisonViagra Online ShopDeath By ViagraSuppliers Of Viagra In UkBuy Viagra In UkBuy Viagra NowTry Viagra For FreeGeneric Viagra On Line CheapOrder Viagra Air TravelViagra DiscountAlternative Doctor ViagraHow Long Will Viagra LastCyalis Levitra Sales ViagraVigorex ForteMail Order Viagra

Apollo Native File Dialogs

with 6 comments

Currently the Apollo Alpha doesn't support native file dialog boxes (it will before the final official release.) Despite that, there is a way to get this functionality now by using existing Flash Player APIs.

I will first show how to display a file 'Save' dialog box which allows the user to specify the name of the file they would like to write to the disk. This will allow them to type in the name of a file that may not exist. The user can also select a file that already exists and the dialog will prompt the user that they are about to replace that file on the system.

To accomplish this in Apollo, you use the 'download' method on the flash.net.FileReference class. Because the flash.filesystem.File class extends FileReference, you can employ this technique by using that class as well. The trick to getting the File reference without actually downloading the file is to cancel the URLRequest before it executes. See the code below for an example:

Actionscript:
  1. private var file:File;
  2.  
  3. private function saveFile():void
  4. {
  5. // Here we create a new File class and wait for the
  6. // 'open' event. The URLRequest can use a URI pointing
  7. // to any resource, we will be canceling it in the event
  8. // handler. It must be a valid URI though. We also specify
  9. // the default name for the file that the user will be able
  10. // to override in the dialog.
  11. file = new File();
  12. file.addEventListener( Event.OPEN, handle_saveFileSelect );
  13. file.download( new URLRequest("http://foo"), "hello.txt" );
  14. }
  15.  
  16. private function handle_saveFileSelect( event:Event ):void
  17. {
  18. // First cancel the download operation. We aren't going
  19. // to download a file but we now have a reference to the
  20. // file the user specified anyways!
  21. file.cancel();
  22.  
  23. // Time to write out some text to the file.
  24. var fileStream:FileStream = new FileStream();
  25. fileStream.open( file, FileMode.WRITE );
  26. fileStream.writeUTF( "Hello World!" );
  27. fileStream.close();
  28. }

Another File dialog that you may want to use is a file chooser dialog. This dialog will only allow the user to select only existing files. We can actually use this API as documented we don't have to cancel any URLRequests like in the previous example.This can be accomplished by using the flash.filesystem.File 'browse' method. Lets take a look at the code:

Actionscript:
  1. private var file:File;
  2.  
  3. private function readFile():void
  4. {
  5. file = new File();
  6.  
  7. // Lets listen for the 'select' event. This event tells us that
  8. // the user selected a file. We can also listen for a 'cancel'
  9. // event that will tell us the user didn't select a file and
  10. // closed the dialog.
  11. file.addEventListener( Event.SELECT, handle_readFileSelect );
  12.  
  13. // Open the dialog box and wait for the 'select' event.
  14. file.browse();
  15. }
  16.  
  17. private function handle_readFileSelect( event:Event ):void
  18. {
  19. // Get a reference to the file and trace out the
  20. // text representation of the file.
  21. file = File( event.target );
  22.  
  23. var fileStream:FileStream = new FileStream();
  24. fileStream.open( file, FileMode.READ );
  25. trace( fileStream.readUTF() );
  26. fileStream.close();
  27. }

To get a reference to more than one FileReference objects, you use the flash.net.FileReferenceList class. I will not show an example of that here, but it follows the same pattern as above. Be sure to check out the FileReferenceList docs.

There are some limitations to these techniques and issues that you should be aware of:

  • There is no directory chooser dialog. You can only select or create file references.
  • You cannot specify an initial directory for the dialog. It will default to the directory of the last file that was selected.
  • Each Apollo application can only have a single file dialog box open at any given time. This means that each window of an Application is limited to the one dialog for its parent application.

I have attached a simple Flex Builder Project file that contains all of the code above.

Written by Daniel Dura

March 29th, 2007 at 6:24 am

Posted in AIR, Actionscript, Tutorial

6 Responses to 'Apollo Native File Dialogs'

Subscribe to comments with RSS or TrackBack to 'Apollo Native File Dialogs'.

  1. Would the sample FileSavePanel.mxml add any different functionality?

    James L

    29 Mar 07 at 6:45 am

  2. James, the sample project doesn’t add any significant functionality. The only thing it does differently is add text fields so that the string you write to the disk can be customized, and when you read from the disk the text will appear in the second TextArea component.

    Daniel Dura

    29 Mar 07 at 7:19 am

  3. Another limitation of this is that the dialog titles will say “upload” and “download”, which may be confusing to users who are just loading or saving a file on their local hard drive. Again though, these are just temporary measures until native dialogs are fully supported.

    Keith Peters

    29 Mar 07 at 8:22 am

  4. [...] And Daniel Dura had a trick to use a native save windows. [...]

  5. Hi Daniel,
    If I use your code as written, I get an IOError after closing the save() popup (i.e. your first example).

    However, if I change the following line:
    file.addEventListener( Event.OPEN, handle_saveFileSelect );
    to this:
    file.addEventListener( Event.SELECT, handle_saveFileSelect );

    the problem goes away.

    Hope that’s helpful,
    Ian

    Ian Thomas

    9 Apr 07 at 12:59 pm

Leave a Reply