Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Losing File reference in Notification body??  (Read 8096 times)
shizny
Full Member
***
Posts: 31


View Profile Email
« 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.



Logged
tobydeh
Port to Python
Sr. Member
*
Posts: 52


View Profile Email
« Reply #1 on: March 10, 2008, 03:44:26 »

How and what was the "fileSelected" method listening to?
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #2 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]);
Logged
tobydeh
Port to Python
Sr. Member
*
Posts: 52


View Profile Email
« Reply #3 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]
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #4 on: March 10, 2008, 08:20:59 »

oops, that was stupid.  Thank you.
Logged
Pages: [1]
Print