Personal tools

SWF7 Conversion

From OpenLaszlo

Case mismatch

This is THE most common problem. view names, function names, variables, all over the place have inconsistent use of case.

Particularly insidious when people have used this idiom to avoid debugger warnings

this['onsafeclick']['sendevent']();

that needs to be sendEvent.

The approved syntax for avoiding debugger warnings is:

<attribute name="onfoo" value="null"/>
<method name="setfoo" args="newfoo">
  this.foo = newfoo;
  if (this.onfoo) this.onfoo.sendEvent(newfoo);
</method>

Old code should be updated to use this syntax.

Unitialized or NULL variables

NaN and undefined are sticky values, once a variable is set to one of these, it will not turn into a number when you do arithmetic on it. This problem tends to occur in code which runs when views are initialized, if they reference attributes that are not yet computed.

  • you can't do foo++ if foo is null or undefined: you get NaN
  • don't take .length of uninitialized or null vars: you'll get NaN
  • NaN is especially nasty in constraints or initializers which affect view size or visibility

Example: spot the bug here:

<view width="${parent.width-parent.tab.width}" height="${parent.height}">
<view name="div" resource="divider_panel" width="${parent.width}" stretches="both"/>
<view name="content" width="${parent.width}" height="${parent.height-div.height}" clip="true"/>
</view>

The bug was that the variable named "div" is not bound in the context of the "content" view. In swf6, adding div.height will be equivalent to adding zero, but in swf7, you get a NaN for the height, and the "content" view does not show up. The author meant "parent.div.height", but this bug was not noticable in swf6.

  • Be very careful about setting _root[somevar] = somevalue. If somevar is undefined, it will set the global undefined to a value, which will screw up everything. We're working on putting a compiler warning in for this case.
  • We sometimes set a method to null to mean do nothing. Calling null is a no-op in AS, but an error in ES.

Proposal: Use function () {} instead.

Lowercase rules: generally attribute names or symbolic values will all be lowercase now

options="releaseToLayout" ==> options="releasetolayout"

Detecting functions

In swf5, a function is == null but true in a boolean context. In swf6+, functions are no longer == null. If you need to know something is a function, you have to say typeof(...) == 'function'.