Functions in a Block
I’m still working on my little Rascal AS compiler and in doing so I encountered some ActionScript strangeness while figuring out some scope rules. Take for example this piece of code:
bc[as].. if ( true )
{
trace ( “entering true clause” ) ;
function hello ( sender : String )
{
trace ( “hello from ” + sender ) ;
}
trace ( “hello function = ” + hello ) ;
hello ( “block” ) ;
}
hello ( “top-level” ) ; // expecting failure: out of (block) scope.
p. According to the ECMAScript 4 standard, this is valid code. One would expect the folowing traced output:
entering true clause
hello function = [ type Function ]
hello from block
However, the actual traced output is:
entering true clause
hello function = undefined
Go figure.. Perhaps I’m missing something, but as it seems Flash ActionScript does not allow named function definitions within a Block. Effectively this would mean that named functions can only be declared at top level (either at a frame or in a class definition’s body) or nested within another function.
About this entry
You’re currently reading “Functions in a Block,” an entry on vanrijkom.org
- Published:
- Monday, August 8th, 2005 at 11:40 am
- Author:
- Ryko
- Category:
- Flash
4 Comments
Jump to comment form | comments rss