meteoric
09-18-2005, 02:53 PM
May I know the different between the following function declaractions:-
==========
Style 1
==========
function test():Void {
trace("success");
}
==========
Style 2
==========
this.test = function():Void {
trace("success");
}
==========
It seems like there are some scoping differences.
I created a flash form app, where I have a root form (called "rootapp") and this root form has a child form (called "childform").
In my childapp, I'm trying to access a function from rootapp, but it seems like I can only get it to work with "style 2", but I don't know the reason.
==========
rootapp
==========
on (load) {
// style 1: cannot be refered from childapp
function test():Void {
trace("success");
}
// style 2: can be refered from childapp
this.test = function():Void {
trace("success");
}
}
==========
childapp
==========
on (reveal) {
_level0.rootapp.test();
}
Also, is there a way to reference rootapp without specifying "_level0.rootapp"? I tried "_root" and "super", but it doesn't work for me.
By the way, I'm using MX 2004 Pro.
Thanks for the help.
==========
Style 1
==========
function test():Void {
trace("success");
}
==========
Style 2
==========
this.test = function():Void {
trace("success");
}
==========
It seems like there are some scoping differences.
I created a flash form app, where I have a root form (called "rootapp") and this root form has a child form (called "childform").
In my childapp, I'm trying to access a function from rootapp, but it seems like I can only get it to work with "style 2", but I don't know the reason.
==========
rootapp
==========
on (load) {
// style 1: cannot be refered from childapp
function test():Void {
trace("success");
}
// style 2: can be refered from childapp
this.test = function():Void {
trace("success");
}
}
==========
childapp
==========
on (reveal) {
_level0.rootapp.test();
}
Also, is there a way to reference rootapp without specifying "_level0.rootapp"? I tried "_root" and "super", but it doesn't work for me.
By the way, I'm using MX 2004 Pro.
Thanks for the help.