I'm afraid we can't help without additional clues. At least we'd need detail on how your variables frame and crossRefTextFrame are defined upstream.
But—agnostically—it's a safe bet that you're dealing with the internationally known “Unresolved Specifier Issue.” That is, your crossRefTextFrame reference is probably not resolved (yet) at the moment you change frame's geometric bounds. Then, hitting the frame specifier causes, for some reason, a collateral effect on the actual receiver of the other variable.
How is it possible? Let's take an example to illustrate this point. Suppose you have this initial setup:
Simple, right? A single-page document, three text frames stacked as shown in the Layers panel, HEAD and FOOT being already positioned in the page while EXTRA stands outside of it, in the spread area. So the following declarations faithfully reflect the initial configuration:
var doc = app.activeDocument, pageFrames = doc.pages.textFrames, // --- head = pageFrames, foot = pageFrames, // --- extra = doc.textFrames.itemByName('EXTRA'); // Let's go dancing...
Then, suppose we reposition EXTRA as follows (before selecting foot):
// Let's go dancing... extra.geometricBounds = [100,-100,150,20]; foot.select(); // Did you guess which block is actually selected?
And the winner is . . .
Why does foot.select() cause EXTRA to be finally selected?!? Because EXTRA now belongs to the page (due to geometricBounds reset), and the foot specifier hasn't been resolved before our move. Syntactically, foot still refers to pageFrames (as originally declared) which now points out to EXTRA (while FOOT has now index 2, with respect to layer ordering.)
Specifiers are resolved only when you hit them through a DOM command, such as select().
Suppose we used this code instead:
// Let's go dancing... foot.select(); // => FOOT is selected (and now *resolved*.) extra.geometricBounds = [100,-100,150,20]; foot.select(); // => FOOT remains selected.
The mere fact of resolving foot before moving extra into the page magically changes the outcome:
As you can see, this very basic example exhibits a 'bug' which is quite similar to the issue you observe in your script. So, you're likely in a case where crossRefTextFrame should be forced to resolve before further processing—using tricks like getElements() and so on. Of course many other factors may be involved in a “Unresolved Specifier Issue,” but that's the big picture.
A very big THANK YOU for taking the time to give me such a detailed explanation on this issue. Just like you suggested the crossRefTextFrame has not been resolved at this point in the code. I had no idea it was important, but because of your example I can understand why. My textframe variables (crossRefTextFrame, footnotesTextFrame etc) are declared by identifying their applied object styles, and as a part of the script I actually change the object style of the crossRefTextFrame. So perhaps that is what confuses the pointer.
And you say you don't feel like training people