all groups > flash actionscript > february 2004 >
You're in the

flash actionscript

group:

When using LoadVars in a class the scope changes in onLoad function


When using LoadVars in a class the scope changes in onLoad function cherry_x
2/5/2004 7:37:36 PM
flash actionscript:

Hi,
I have created a class for a component I created using Flash 2004 MX Pro 7.0.1.
Within this I set an onload function for LoadVars and perform a send and load e.g.

The problem is that when the onload function (readTipList) is executed in a class object, the scope ("this") changes from the the class object, to the LoadVars object ("httpVars"). This does not happen when it is execute outwith a class (e.g. as a frame action).

Is this supposed to happen or is it a bug in MX?
Thanks, Dan

class blah extends MovieClip{
var httpVars:LoadVars;

function callHttp(){
httpVars=new LoadVars();
httpVars.onLoad = readTipList;
httpVars.sendAndLoad(appInterface, httpVars);
}

function readTipList(success:Boolean){
if (success == true) {
this.listTips.display(httpVars.retxml);
}
}

}

Re:When using LoadVars in a class the scope changes in onLoad function jallred
2/5/2004 7:46:26 PM
Do you mean "this" inside the loadvars onload function? If so, the answer might be to assign "this" to a variable and then use that variable in place of this inside of onload.

var myParent = this;

receiveMyData.onLoad = function(){
outsideVar = myParent.someThing; (instead of this.someThing)
}

I'm not sure if that is what you are looking for, but maybe it will help.

Re:When using LoadVars in a class the scope changes in onLoad function cherry_x
2/5/2004 7:56:32 PM
Yes,
This is the workaround I have been using. But I still wonder whether this behavior is to be expected or a bug in MX....

Thanks, Dan


AddThis Social Bookmark Button