Thanks for the reassurance, Cliff!
Ok, I will post a review for the book, when Iím done reading it.
RangeError: Error #1125: The index -1 is out of range 0.
In Details/ItemInfo View: If you keep deleting all the items until just the parent (Story) remains, then you go on and save the changes, when you try to edit the story again it throws an error like the one above.
Thatís the case of a Simple Story, where a Scene is the direct descendant of a Story. story.scenes.length is 0, therefore story.scenes.length-1 is -1. And thatís because the xml file contains no Scenes, just a Cast and a Milieu.
The same happens with a Normal and/or a Complex Story, but this time the arrays in question are story.chapters and story.parts, the first descendants of a Story that EditStoryCommand is trying to set.
- So my first workaround was concentrated on EditStoryCommand and I simply checked the length of the arrays and if it was 0 I added the missing parts to their parents.
For a Simple Story it would look like this:
if (story.scenes.length == 0)
scene=story.scenes[story.scenes.length - 1];
Here the modified code for EditStoryCommand: https://gist.github.com/1524621
- Then I saw that StoryVO has these methods: getNewScene(),getNewChapter(),getNewPart() and I used them like this:https://gist.github.com/1533524
It solves the problem, but it doesnít feel quite right.
When you create new stories the flow looks like this:
So it should be enough to call
scene=story.getNewScene();when story.scenes.length == 0 for a simple story,
chapter=story.getNewChapter (); when story.chapters.length == 0 for a normal story,
or part=story.getNewPart(); when story.parts.length == 0 for a complex story
like when you create a new Story.
But it doesnít work, and right now I canít see why. As I said, Iím not familiar enough with the code yet, so I just modified EditStoryCommand to make it work .
Anyway, I think that I made the changes in the wrong class.
Maybe the real solution would be to prevent saving an empty Story in the first place? Does it make sense to have a Story with no Scene or Chapter or Part, depending on the type of the Story?
I will investigate this chain:
to see what happens in the VOs after deleting an item.
Iím sure there is a very simple and more elegant solution to this and Iím curious to hear it from you.
Then there were the following situations, which I canít reproduce anymore right now:
a. a totally empty XML file has been saved on the hard disk. If you try to edit it, a new Story, called Story 0, gets created and the xml file is empty. Now there are 2 empty stories, which cannot be deleted or edited (RTE)
Also in StoryProxy. loadStory() storyStub.uid is the id listed in index.xml while story.uid is different (a new uid). I donít understand the logic in there yet.
Quick and dirty solution(no idea if it wonít produce other bugs elsewhere):
if (storyStub.uid == story.uid)
cacheProxy=new Proxy(story.uid, story);
cacheProxy=new Proxy(storyStub.uid, storyStub);
b. the story/index.xml contains stories that donít exist in that folder. Of course, when you try to load such a story it throws an error.
So my quick and dirty workaround was this:
private function readFile(file:File, voStub:ValueObject=null):XML
var stream:FileStream=new FileStream();
var xml:XML=new XML();
I think something goes wrong with the updating of the index file (synchronisation between the list of stories in the index and the files on disk)
Iím sorry that I canít provide more accurate info at this stage. I know that my solutions arenít good, and they only show how limited my understanding of the code is, but at least youíll have some hints at the vulnerable parts of the app.