What is the highest unique identifier?
Added: 19 Jan 2011. Working example for Java.
Every definition (image, shape, etc.) in a Flash file must have a unique identifier. The first step processing a Flash file is to find out the highest value used so any new definitions added will not clash with an existing one*.
Finding the highest identifier used in a movie, or movie clip is as simple as finding the number of frames.
int uid = 0; DefineTag definition; for (MovieTag object : list) { if (object instanceof DefineTag) { definition = (DefineTag)object; if (definition.getIdentifier() > uid) { uid = definition.getIdentifier(); } } }
Normally identifiers are added/used in ascending order in a Flash (.swf) file so it would be faster to start the search at the end of the file and simply stop at the first DefineTag found.
int uid = 0; final int count = list.size(); MovieTag object; DefineTag definition; for (int i = 0; i < count; i++) { object = list.get(i); if (object instanceof DefineTag) { definition = (DefineTag)object; uid = definition.getIdentifier(); break; } }
However ascending identifiers are typical but not guaranteed so checking all the definitions is the safest approach.
If performance is really, really critical (but beware of premature optimization) you could pre-process the file to move all the object definitions to the first frame of the movie. This might incur a delay in the movie starting up if there were a lot of objects to load but that would allow you to stop the search once the first frame was completed.
int uid = 0; DefineTag definition; for (MovieTag object : list) { if (object instanceof DefineTag) { definition = (DefineTag)object; if (definition.getIdentifier() > uid) { uid = definition.getIdentifier(); } } else if (object instanceof ShowFrame) { break; } }
*Tracking the identifiers used in a file used to be formed by the FSMovie class in version 2 of Transform SWF. This was removed from version 3 so the tracking of identifiers is performed by a simple counter in the application instead. This made the code more readable compared to using method calls on movie.