This content has been marked as final. Show 4 replies
Are all the frames in your story labeled "LeftTF"?
I suspect that myTextFrame is actually a multi-object specifier, so when you get the parentStory, you're actually getting the parentStory of all the text frames with that label, which happens to largely be the same story over and over.
Ahh, you're spot on, as usual!!! I do have 191 text frames labeled "LeftTF", two of which are on the master pages--which explains why two of the 191 story ids are different than the others. I confirmed this behavior in a new document that I created by hand. I created four frames with the same label value and flowed a story through them all. I got the multiple story result.
But I am still confused, and I think I need some education. When I call:
var myTextFrame = myDoc.textFrames.itemByName("LeftTF");
I get a single TextFrame object, not 191 of them (which I actually was concerned with when I started writing the code). Since I only got one TextFrame, I figured it returned the first one in the collection or something. So, is myTextFrame in the code above a reference to all TextFrames that have a label with the value of "LeftTF", or just a single TextFrame object?
Also, the Object Model Browser from the ESTK Help menu states that TextFrame.parentStory returns a Story object, not an array of Story objects. Is this just a documentation issue?
Thanks for all of your help!!!!
re: "I get a single TextFrame object, not 191 of them (which I actually was concerned with when I started writing the code). Since I only got one TextFrame, I figured it returned the first one in the collection or something. So, is myTextFrame in the code above a reference to all TextFrames that have a label with the value of "LeftTF", or just a single TextFrame object?"
In the example above, myTextFrame appears as a single text frame object, but is, in fact, all of the text frames that have the label. (You can also use myDoc.textFrames.item("LeftTF") due to the special case label=name behavior of page items.) If you look at a value inside that text frame object (such as parentStory), you'll see arrays. (This is one of those "The Data Browser is your Friend" moments.)
This seems peculiar, but it also seems to be the way it's been for some time. I hadn't really noticed--I was pretty sure it would return an array or a collection of text frames. The way that it's working is definitely handy (because when you're getting references to all of those objects, there's probably something you want to do to all of them), and it's probably by design.
For now, at least, it looks to me as if the way to iterate through the text frames is to use the id property of the returned text frame object. Just get the ids listed there and use them to specify references to text frames.
Ahh...I see what you mean! Thanks!
FWIW, I did look in the data browser during my initial confusion, but I only checked the variable's type and didn't look inside its properties. Silly me, I thought that I knew what the properties would contain! ;-)
I was sort of expecting to get an array (or collection) of TextFrame objects from the itemByName() call. I certainly wasn't expecting to get an array of Story objects from the TextFrame.parentStory call. The parentStory call happened so far down in the code from the itemByName() call (about, what, three whole lines!) that I forgot what I was doing!!! ;-)
So, it seems like one needs to be careful when using itemByName(). This was a good learning experience for me. I'll have to try to remember this should it happen again. I love this forum because I will probably, once again, find the answer to a problem I am having where my name appears in the solution thread. 8-|
As it turns out with most situations like this, my overall algorithm turned out to be flawed, so I'm not even using the code. Why do I enjoy coding so much?