« DeadMotion | Main | JSFL Docs Now Available! »
November 08, 2003
Export-time SWF Version
Say you have some code that hasn't been ported to Flash MX 2004. How can you warn the user when the code is used in a version 7 SWF? You can check how your code is compiled (or executed in this case) easily, because SWF7 is case-sensitive while SWF6 is not.You might do it like this:
a=1;
A=2;
if (a!=A)
trace("Not yet compatible with SWF 7");
Of course there are other differences too, but this will do.
What about SWF5 and SWF6?
Action Greater action was introduced with SWF6. For SWF5 and below, it is emulated by reversing the arguments and using ActionLess action followed by an action ActionNot.
In a version 5 SWF,
(x>y)will compile as
not(y<x)As stated in the SWF specs, this sometimes caused surprises. Using this information, we can have the following line:
if (not(b>b++)) trace("Must export SWF 5");
For the sake of the discussion, lets continue with SWF4. In SWF4 there's no real boolean type and true/false values. So,
if (String(c==c)!="true")
trace("Exported to a version 4 SWF");
or if (1===true) trace("Aha! exported to SWF 4!");
will do the detection.
One thing to note is that except the first one, these detections are compile time only for detecting the version SWF is published.
To sum it up, the following snippet will work in Flash 5, MX, MX 2004, and can detect the compile-time export/publish version of the SWF at run-time (So it won't work run-time in a loaded SWF to detect version of the main SWF etc.):
if (x=(X=1),x>(X++)) {
if (String(x==X)!="true") trace ("4");
else trace ("5");
} else if(x==X) trace ("6");
else trace ("7 or above");
You could probably get the settings using JSAPI and do a similar detection, but that won't work with Flash MX or 5.
Notice the capitalizations on line 2 and for the second X on line 1; they are not necessary. But it looks cool this way...
(ActionScript HighLighting by shockwave-india.com).
November 8, 2003 in Flash | Permalink
TrackBack
TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c73d553ef00d83422767953ef
Listed below are links to weblogs that reference Export-time SWF Version:
Comments
Great info! Thanks Burak...
Posted by: Jonas Galvez at Nov 8, 2003 5:51:05 PM