Strict Equals, SWF 5, Flash MX and 2004

Strict Equality (===), for which a bytecode was introduced with SWF 6, works like the Equality operator (==) except that the data types must also be equal.

 
When you export to SWF 5, Strict Equals is converted to equivalent bytecodes.

 
For example, the following code when exported to Flash 5,

if (a === b) {}

will compile to:

var _local1 = a;
var _local2 = b;
if (((typeof (_local1) == typeof (_local2)) ?
(_local1 == _local2) : true)) {}

by Flash MX 2004; and to:

var _local1 = b;
if (((typeof (a) == typeof (_local1)) ?
(a == _local1) : false)) {}

by Flash MX.

 
Notice the difference how one returns false and one returns true, if the types are not equal. Now, it seems what Flash MX doing is correct here.

 
You can test this by the following code, using Flash MX 2004 and exporting to SWF 5 and 7:

a=1;
b="1";
if (a===b){
trace("Yes");
} else {
trace("No");
}

When exported to SWF 5 by Flash MX 2004, you’ll see that it will trace ‘Yes’ unexpectedly…

 
Another problem with Strict Equals, MX 2004 and SWF 5 export is there when using the Switch statements.

 
Switch statement was introduced with Flash 6, it doesn’t have a corresponding bytecode but compiles to series of If statements. In Switch / Case statements always Strict Equals is used.

 
At this point you might think that since there seems to be a problem with MX 2004 and Strict Equals when exporting to SWF 5, it’s just another view of the same problem, which might get overlooked since you won’t be coding Strict Equals manually.

 
But, no, the problem is that Flash MX 2004 exports Strict Equals bytecodes, which should not be recognized by Flash Player 5. Flash MX exports correctly converted bytecodes in this case again.

 
So beware when exporting to SWF 5 with Flash MX 2004…

 
And if you were wondering, for SWF 4, it’s not possible to emulate Strict Equals because everything internally is more or less a string.

This entry was posted in Flash.

4 Responses to Strict Equals, SWF 5, Flash MX and 2004

  1. Gary says:

    Hi Burak,
    Yes, we recently learned about this bug on the Flash team. It is being tracked to be fixed in our next major release.
    Gary Grossman
    Director of Engineering, Flash

  2. Issues (or bugs) will always be there with any software. It’s amazing to see how fast and positively Macromedia acts responding to any issue with Flash. This is, IMHO, what makes Flash (and Macromedia) a great choice.
    And I must admit, it feels good when Gary Grossman posts a comment in your blog.

  3. According to the release notes at http://www.macromedia.com/support/documentation/en/flash/mx2004/releasenotes.html , and my tests, this issue is fixed with Flash MX 2004 7.2.
    Best regards,
    Burak

  4. Now another issue you need to be aware of when using switch statements with MX2004 is to never use multiple expressions or statements in ‘case’ statements.
    Like assigning a variable in the case statement:
    x = “B”;
    var y;
    switch (x) {
    case y=”A”, y :

    Best regards,
    Burak