简体   繁体   中英

AS3 Flash SWF File Versioning

I've looked all over online and can't seem to find a way to put a version number in a swf file. We need to know which version of the swf file we have on different machines, so we had thought of maybe writing a file if it does not exist to the swf directory, containing the swf version number. We are not using Flex and as3, so that's not going to work since we can't write to the disk. So i've been looking around and haven't been able to find where we might specify the file version of our swf to something like "14.06.30".

Is there a way we might be able to set the version of our swf file?

We've thought about using a key press to display a version number, but we don't want to do that because the swf can load in other swf's where keypresses might mean something else. This would be a last resort.

For version numbering in the swf, we use a compile constant http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7abd.html . For example: -define+==CONFIG::VersionString,'{svn version}' With Flash builder you can add this to your additional compiler settings, or set this variable in your Continuous build script. In your actionscript you can read this var with 'CONFIG::VersionString'.

We add this version number to the context menu in the swf (right click menu).

package {
import flash.display.Sprite;

public class Test extends Sprite
{
    public function Test()
    {
        super();
        addVersionToContextMenu();

    }

    private function addVersionToContextMenu () : void
    {
        var item:ContextMenuItem = new ContextMenuItem("Version: " + CONFIG::VersionString);
        var items:Array = this.contextMenu.customItems;
        items.push(item);
        this.contextMenu.customItems = items;
    }
}

}

If you right click on the swf it looks like:

在此处输入图片说明

You can use a SharedObject to store and retrieve the version number:

var sharedObject:SharedObject = SharedObject.getLocal("versionNumber");
var versionNumber:String;
if(sharedObject.data.value)
{
    versionNumber = sharedObject.data.value;
}
else 
{
    // no version number has been set, set it here
    versionNumber = "14.06.30";
    sharedObject.data.value = versionNumber
    sharedObject.flush();
}

If you have a SharedObject reader (I recommend .minerva ) You can retrieve the set value without even opening the swf. Just open the .sol file.

For SWFs, .sol files are stored in C:\\Users\\[USER-NAME]\\AppData\\Roaming\\Macromedia\\Flash Player\\#SharedObjects\\[random sequence of characters]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM