Poor man's flash version control
Flash version control is a big topic, but the intention of this article is not. Since most source file version control system such as SVN does not handle binary files like fla or swf, it's really hard to keep track of the version of a fla file.
Is there really nothing we can do?
This article introduce a JSFL script that provides the basic functionality of version control by recording a version number (and increase it too), as well as by who and at what time a fla file is edited automatically.
What this script does, is adding version info to the fla file you are working with. Every time you run the script, it automatically increase the version number, record the name of the people(name and personal info are written in the script) who edit it and the time of the edit in the first frame of the fla. When you pass the file to your co-workers later, he will know who edited this file and when by the time he open the file. If he has installed this script too, his name and edit time will be automatically recorded to the file when he edit the file too.
I call it poor man's flash version control. Although it may seems primitive, but it really works.
The version number is written in the frame as both comment and variable so apart from reading it in the AS edit panel, you can also display the variable by putting a dynamic textfield in the stage with the setting of display that version number variable. When you test your swf later, you can easily see the version number so it can efficiently eliminate the possibility of several common mistakes such as using a wrong file or forget to clear browser buffer when testing the swf online.
Here is the code:
YourName="Your Name (Your Contact info)";
function changeVar(as,name,value,sep){
if(sep==undefined){
sep="=";
}
if(as.indexOf(name+sep)!=-1){
var s=as.indexOf(name+sep);
var e=as.indexOf(";",s);
var e2=as.indexOf("
",s);
if(e==-1){
if(e2!=-1){
e=e2;
}else{
e=as.length-1;
}
}
var str=as.substring(s,e);
if(value=="++"){
var ns=name+sep+(Number(str.split(sep)[1])+1);
}else{
var ns=name+sep+value;
}
return as.split(str).join(ns);
}else{
if(value=="++"){
value=1;
}
return name+sep+value+";
"+as;
}
}
var as=fl.getDocumentDOM().timelines[0].layers[0].frames[0].actionScript;
as=changeVar(as,"build_num","++");
as=changeVar(as,"build_time",new Date().getTime());
as=changeVar(as,"//Modified by "+YourName,new Date()," at ");
fl.getDocumentDOM().timelines[0].layers[0].frames[0].actionScript=as;
fl.saveDocument(fl.getDocumentDOM());
fl.getDocumentDOM().testMovie();How to install
- Create a new jsfl file, copy the above code.
- Be sure to modify the first line with your own name.
- The last 2 lines are optional, you can find their purpose later.
- Save it to this path:
Documents and Settings/<your login id>/Local Settings/Application Data/Macromedia/<your flash version>/<language>/Configuration/Commands/ - Check out the command menu in your Flash, you should be able to see a new item.
After you run the script by clicking the new menu item, go to your fla file's first scene, click on the first frame with a "a" mark. You will find several lines of codes like the following at the beginning of the script panel.
//Modified by Your Name (Your Contact info) at Sat Mar 10 11:25:01 GMT+0800 2007;
build_time=1173497101406;
build_num=684;The first line states the author and modify date.
The second line is the variable for build time.
The third line is the variable of version number, every time you run this script, this number will be increased by 1.
To make the script even smoother integrated into your everyday working, you can assign a keyboard shortcut to it. For example assign it to ctrl-enter, then every time you test your fla file, the version info is automatically written to the file. Now go back the the code display above, remember those last 2 lines? Their purpose is here. While replacing the functionality of ctrl-enter, the last 2 lines of the code will do the job of the replaced command, so you won't feel any difference.
Here's how to assign keyboard shortcut in Flash:
- In flash's menu, Click Edit -> Keyboard Shortcuts...
- Duplicate a setting from the default one
- Find Control -> Test Movie
- Delete the default Ctrl-Enter
- Then go to Commands -> [your jsfl name]
- Set it to Ctrl-Enter
- It's done!
Enjoy!
