LoadVars inside class - how?

How can I use LoadVars inside a class?
I mean, if I assign the method name to onLoad of LoadVars, the method will be override, and will not pertence to my class.
look this:

[AS]
class myClass{
var lv:LoadVars;
function myClass(){
lv = new LoadVars();
lv.onLoad = onLoad;
}
function onLoad(sucess:Boolean):Void{
trace(this);
}
function trigger(){
lv.sendAndLoad(“testeURL”,lv,“POST”);
}
}
[/AS]
this at onLoad function points to loadVars not to myClass.

the only solution I found to this was to myClass extends LoadVars, but it limit me since AS 2 does not support multiple-Inheritance.

I think I will face the same problem with all others components that does not has addEventListener capabilitie.:red: :red:

Other solution could be extend the LoadVars and add the eventListener capabilitie.

you people have any idea?

I must say that I don’t know much about OOP in AS 2.0, but I think I know why tracing this returns the loadVars object and not myClass.

You have set lv.onLoad equal to the function “onLoad”. That means that, when lv.onLoad is executed, it will execute onLoad. Because you are using this inside the onLoad function, and lv.onLoad is executing that function, this will return the LoadVars object.

Have a look at this example:


traceThis = function(){
	trace(this);
}
this.createEmptyMovieClip("bleh",1);
bleh.onEnterFrame = traceThis;

This is the same as:


this.createEmptyMovieClip("bleh",1);
bleh.onEnterFrame = function(){
trace(this);
}

The same is happening with your onLoad function. Because it’s lv executing it, this will point to lv.

You are completly right!

I don’t know about flash, but others OOP language implicitly passes the “this” to the first parameter on every call to a method. Of course you didn’t see that.

[AS]
class myClass{
function myMethod(this,x,y){
// the this variable is passed implicity by the compiler.
// since onLoad receive a pointer to the class,
// loadVars implicity passes his this at the first parameter.
}
}
[/AS]

LoadVars exists since flash 5, so I think he is not ready to work with class.