The narrow scope of the function takes precedence over the bigger scope of the frame or class. The compiler won't get confused. But you might.
To reference the instance-scoped variable within the function, use "this.type". If it isn't a property of the instance (such as a variable declared in another enclosing function), you can't reference it directly, you'd have to save it to another variable.
Code:
public class ScopeTest{
private var foo:String;
private function ScopeTest(){
foo = "instance value";
}
private function testMethod(foo:String):void{
trace("testMethod result: "+foo);
}
private function testNested(foo:String):void{
trace("outer testNested value: "+foo);
var bar:String = foo;
trace("class value is still: "+this.foo);
function nested(foo:String):void{
trace("inner testNested foo value: "+foo);
trace("inner testNested bar value: "+bar);
}
nested("nested inner value");
}
public function test():void{
trace("class instance value: "+foo);
testMethod("method param value");
testNested("nested outer value");
}
}
invoke as such:
Code:
var st:ScopeTest = new ScopeTest();
st.test();
should output:
Code:
class instance value: instance value
testMethod result: method param value
outer testNested value: nested outer value
class value is still: instance value
inner testNested foo value: nested inner value
inner testNested bar value: nested outer value