PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: shizny on March 09, 2008, 06:17:11



Title: Losing File reference in Notification body??
Post by: shizny on March 09, 2008, 06:17:11
I have a mediator for a form that sends a notification (body of note is event.target which is a file that has been selected) out to a command, the command relays the info to a proxy, and the proxy delegates loading of file and then returns a notification.  I keep on getting this error that says

TypeError: Error #2007: Parameter file must be non-null.
   at flash.filesystem::FileStream/open()

I'm tracing out the note.body(), throughout the process and it is good until I actually try and open the file.  Am I not casting things in the right manner, not passing info in the notification correctly? 

Here are little snippets of the process. 

In the mediator

:
public function fileSelected(event:Event):void {
getImportNewGameData.filePath = event.target.nativePath;
sendNotification( ApplicationFacade.IMPORT_FILE_SELECTED, [ event.target ] );
}

In the command
:
override public function execute( note:INotification ) :void   
{
            // Get the ImportFileProxy
            var importFileProxy:FileProxy = facade.retrieveProxy( FileProxy.NAME ) as FileProxy;
            importFileProxy.loadFile(note.getBody());

        }

the proxy
:
public function loadFile(event:Object):void
{
// create a worker who will go get some data
// pass it a reference to this proxy so the delegate knows where to return the data
trace("This is the file name from FileProxy:"+event);
var delegate : LoadFileDelegate = new LoadFileDelegate( this );
// make the delegate do some work
delegate.loadGSISFile(event);
}

and finally the helper where I'm getting the error.
:
public function loadGSISFile(event:Object) : void
{
theFile = event as File;
var stream:FileStream = new FileStream();
    stream.open(theFile, FileMode.READ);
    var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
    trace("This is the file data: "+fileData);
    this.responder.result(fileData);

}

Does anybody know what I'm doing wrong.





Title: Re: Losing File reference in Notification body??
Post by: tobydeh on March 10, 2008, 03:44:26
How and what was the "fileSelected" method listening to?


Title: Re: Losing File reference in Notification body??
Post by: shizny on March 10, 2008, 07:25:11
It is listening to the event.select here...

:
getImportNewGameData.browseGood = true;
var gsisFilter:FileFilter = new FileFilter("GSIS", "*.xml");

getImportNewGameData.importFile = new File();
getImportNewGameData.importFile.addEventListener(Event.SELECT,fileSelected);
getImportNewGameData.importFile.browseForOpen("Select GSIS File for import", [gsisFilter]);


Title: Re: Losing File reference in Notification body??
Post by: tobydeh on March 10, 2008, 08:10:49
You are passing an array, not the File() Object..

sendNotification( ApplicationFacade.IMPORT_FILE_SELECTED, event.target );

NOT

sendNotification( ApplicationFacade.IMPORT_FILE_SELECTED, [ event.target ] );

otherwise you would have to use note.getBody()[0]


Title: Re: Losing File reference in Notification body??
Post by: shizny on March 10, 2008, 08:20:59
oops, that was stupid.  Thank you.