Erain 3D
--> FDT Pure coding comfort


Using a Single Code Base with Sandy 1.1 and 1.2

I've been using Sandy 1.1 because it is stable, but I wanted to try out some things in Sandy 1.2. I wanted to conditionally compile different parts of my code for each version (to handle the differences between the libraries).

For details on what's changed in Sandy 1.2, see here.

One solution is to use a preprocessor to conditionally compile code. See also Conditional Compilation with MTASC and Mike Chambers' blog post on conditional compilation.

However, to my knowledge Flash 8's authoring tool doesn't support conditional compilation and I didn't want to bother with a preprocessor.

Here is an easy way to fool Flash's syntax checker to prevent compile-time errors due to differences in the Sandy 1.1 and Sandy 1.2 libraries. WARNING: This also defeats the ability of Flash to warn you if your parameters are of the wrong type.

The basic trick is to use an untyped variable as the constructor name. Below, I use tmpCam and tmpScreen instead of Camera3D and ClipScreen, thus preventing compiler errors.

I define the “version” variable as “1.1”, or “1.2”.

 var version = "1.1";

 var tmpCam = Camera3D;

 if (version == "1.1") {
    var tmpScreen = ClipScreen;
    var screen:ClipScreen = new tmpScreen(mc,250,250);
    var cam:Camera3D = new tmpCam(350,screen);
 } else {
    var cam:Camera3D = new tmpCam(350,350);// 1.2
 }

You can do similar things for other methods that vary between Sandy 1.1 and 1.2 (see the FAQ on the main web site for details on these)

For example, you can do this for enableBackFaceCulling, which is a property in Sandy 1.1 but a method in Sandy 1.2

 var version = "1.1";

 var tmpObj = theRealObj;

 if (version == "1.1") {
    tmpObj.enableBackFaceCulling = true;
 } else {
    tmpObj.enableBackFaceCulling (true);
 }

The only thing you have to do manually (besides changing your version variable) is set the classPath to point to the correct Sandy library for 1.1 or 1.2.

Don't forget to delete your ASO files when you switch between different versions of the Sandy libraries

You can address this by having two shell FLA files, each with different classPaths set under their Publish Settings (not under Preferences, which applies to all .FLAs)

It would also be possible to patch the World3D class in the Sandy 1.1 and Sandy 1.2 libraries to return the build number, so your code could check that value instead of a manual version number. I've committed such a change to the Sandy 1.2 SVN repository. The new method is World3D.getVersion() and it returns the string “1.2” in Sandy 1.2. If you want to patch your Sandy 1.1 World3D.as file, add this code:

private static var _version:String = "1.1";
  
public static function getVersion( Void ) : String
{
	return _version;
}

You could also add similar patches to compensate for the differences between Sandy 1.1 and Sandy 1.2 to ensure forward compatibility. I committed some changes, for example, that support addCamera() in Sandy 1.2 just like it was supported in Sandy 1.1. That saves you the trouble of changing your addCamera() invocation to setCamera().

Cheers,

Bruce - zeusprod