Hi,
If I understand correctly - commands are created then they respond to notification, and garbage collected after job is done. Both actions are expensive.
as long as you read and listen to what everybody tells :
commands must be stateless! there should not be a problem to create command once, and keep it in memory for future uses.
Also keeping one object with execute instruction in memory should not be a problem. It will take couple of bytes.. not more.
Object creation and destruction could be avoided?
Apart of danger of creating the state and fail with it, is there any other problems?
-------------------
while I am at it...
do you think this command is valid, I mean.. it kind of... sort of.. has a state for very short time until file is selected and ether fails or is loaded. (state in dynamic memory... but still)
package com.mindscriptact.mapExplorer.controller.fileHandling {
public class LoadZoneFileCommand extends SimpleCommand {
override public function execute(note:INotification):void {
var fileReference:FileReference = new FileReference();
fileReference.browse([new FileFilter("map3d.xml Files", "*.xml")]);
fileReference.addEventListener(Event.SELECT, handleFileSelect);
}
private function handleFileSelect(event:Event):void {
var fileReference:FileReference = event.currentTarget as FileReference;
fileReference.removeEventListener(Event.SELECT, handleFileSelect);
//
fileReference.addEventListener(Event.COMPLETE, handleFileLoadComplete);
fileReference.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
//
fileReference.load();
}
private function handleFileLoadComplete(event:Event):void {
var fileReference:FileReference = event.currentTarget as FileReference;
fileReference.removeEventListener(Event.COMPLETE, handleFileLoadComplete);
fileReference.removeEventListener(IOErrorEvent.IO_ERROR, handleIOError);
sendNotification(Note.PARSE_MAP_DATA, fileReference.data);
}
private function handleIOError(event:IOErrorEvent):void {
var fileReference:FileReference = event.currentTarget as FileReference;
fileReference.removeEventListener(Event.COMPLETE, handleFileLoadComplete);
fileReference.removeEventListener(IOErrorEvent.IO_ERROR, handleIOError);
sendNotification(Note.ERROR_REPORT, " ERRROR: file error " + fileReference.name + " " + event.text);
}
}
}
would you implement it differently?
Thanks for time.