File browsing/uploading/saving is a common task. What is the best way to implement file handling while using the PureMVC framework?
Below I propose a foundation for handling file browsing/uploading/saving in a single-core PureMVC application.
In both single-core and multi-core PureMVC applications, I tend to keep all of the FileReference/FileReferenceList event handling in a Proxy. This allows for application/module -wide handling/presentation of errors related to file uploading. It also abstracts the code for re-use in all of your components in the application.
The provided project is a foundation and provides the ground work for your project. You can easily add more functionality. The project is set to compile to flash player 10 out of the box. If you aren't able to use FP10, simply change the requirements to FP9 in the project properties. The example doesn't _currently_ use any FP10 specific FileReference features so you can simply switch. Though, I recommend checking it out => http://theflashblog.com/?p=463.
The best explanation is simply running the application and following the output. Every object informs you of what notifications it has handled and what phase/type it is in. If you aren't familiar with PureMVC, that is usually one of the better places to start understanding the application's flow.
In case you aren't running the application, here is the result from launching the application, browsing to and selecting a local file, and clicking "Save".
[main.load (creationComplete)] facade.startup() [ApplicationFacade.startup] sendNotification: ApplicationFacade.STARTUP => Application.REQUEST [StartupCommand.execute] Register FilesProxy [...StartupCommand.execute] Register ApplicationMediator [...StartupCommand.execute] sendNotification: ApplicationFacade.STARTUP => ApplicationFacade.RESPONSE [ApplicationMediator.handleNotification] ApplicationFacade.startup => ApplicationFacade.response [ApplicationMediator.handleFileUploadEvent] FileUploadComponentEvent.browse [FileBrowseLocalCommand.execute] ApplicationFacade.REQUEST [ApplicationMediator.handleNotification] ApplicationFacade.fileBrowseLocal => ApplicationFacade.request [FilesProxy.handleFileReferenceEvent] select [ApplicationMediator.handleNotification] ApplicationFacade.fileBrowseLocal => ApplicationFacade.response [ApplicationMediator.handleFileUploadEvent] FileUploadComponentEvent.save [FileUploadLocalCommand.execute] ApplicationFacade.REQUEST [FilesProxy.handleFileReferenceEvent] complete [ApplicationMediator.handleNotification] ApplicationFacade.fileUploadLocal => ApplicationFacade.response [ApplicationMediator.handleNotification] ApplicationFacade.fileUploadLocal => ApplicationFacade.request
I also recommend that you check out the docu and other materials at PureMVC.org
If you have any questions, feel free to post a comment here or on my personal blog blog.wintondeshong.com.