Skip to main content
Participant
December 28, 2016
Question

Local variables have backwards scope in AIR 23

  • December 28, 2016
  • 1 reply
  • 311 views

Hi!

Upon updating to latest AIR to rebuild my iOS app with iOS 10 support, I have run into an incompatibility, and narrowed it down to a change in scope behaviour of locally declared variables.

Formerly, a locally declared variable was only accessible starting from wherever it was declared and retaining the scope until the end of a function. Currently, a locally defined variable is scoped backwards and can be accessed from the beginning of the function, even before its declaration, even if it is declared in a deeper scope. This poses issues when local variables are named exactly the same as class properties.

Below is a reproduction snipped.

package {

     import flash.display.Sprite;

     public class Main extends Sprite {

          public var a:Number = 4;

          public function Main() {

               trace(a); // NaN

               if (true) { var a:Number = 0; }

               trace(a); // 0

          }

     }

}

I would like to inquire whether this is a bug, and undocumented language specification change, or undefined behaviour.

Cheers!

Sos

EDIT:

Apache Flex, and previous versions of Adobe AS3 compilers would trace 4 and 0, respectively, as expected.

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
December 28, 2016

I am only able to get the expected 4,0. I tried with AIR 23 and 24. Are you doing AIR for desktop, iOS, or Android? Does it only fail on devices?

Participant
December 28, 2016

Hmmm... weird, I wonder what am I doing wrong, then. Targetting Flash Player 23.0 does this (as played back from Flash Player content debugger 24.0). No warnings.

Here's a build log from Flash Develop:

Running process: C:\Program Files (x86)\FlashDevelop\Tools\fdbuild\fdbuild.exe "C:\code\test\test.as3proj" -ipc XXXXXXX -version "23.0.0" -compiler "C:\AIR" -library "C:\Program Files (x86)\FlashDevelop\Library"

Building test

mxmlc-cli -load-config="C:\AIR/frameworks/flex-config.xml" -load-config+=obj\testConfig.xml -debug=true -swf-version=34 -o obj\testXXXXXXX

Running java as: java

Loading configuration: C:\AIR\frameworks\flex-config.xml

Loading configuration: C:\code\test\obj\testConfig.xml

646 bytes written to C:\code\test\obj\testXXXXXX in 0.472 seconds

Build succeeded

Done(0)

[Capturing traces with FDB]

NaN

0

AIR config files have not been edited from their original state.

Colin Holgate
Inspiring
December 28, 2016

Can you put your swf online somewhere?