Groups | Blog | Home
all groups > flash actionscript > january 2006 >

flash actionscript : OOP class scope problem


stephan.k
1/10/2006 9:36:05 PM
Hi Everyone

I have an issue with class scope of a .as class. I am using the sendAndLoad
function to send information to a php file. I am sending the info with a
loadVars object and load the info with an XML object. Within the XML object
"onload" function however I can't get a grasp of how to get back to the scope
of the class...

If you have any ideas or thougts on this please let me know. I'd appreciate
it.


Many thanks in advance.

Stephan

Here are the most important parts of the code:

////////////////////////////////////////////////////////////////////////////////
////////////

import com.cityofmemory.CofmConverter;


class com.backend.AddAStory extends com.backend.Scripts{

private var thisObj:AddAStory;

[....]

public function AddAStory(){
[...]
var thisObj=this;

}

[...]

public function sendLocationData(){
recXML = new XML();
recXML.ignoreWhite = true;
sendLV = new LoadVars();

sendLV.variableName = storyData.x;

var thisObj = this;
sendLV.sendAndLoad(SCRIPT,recXML); //the script is defined in the
globalVariables.as
recXML.onLoad = recLocationData;
}
private function recLocationData(success){
trace(thisObj.recXML); //this complies but doeesn't work. traces
undefined
trace(this); //this shows the xml
structure
trace(this.firstChild); //the code does not compile.
Error: this has no properties called firstChild
}
}
LuigiL
1/11/2006 8:33:56 AM
With this code you need a static ref to the class:
stephan.k
1/11/2006 3:24:56 PM
Thank you very much for your reply. The code works which is fantastic!

I have 2 more questions:

1. I am new to static variables but from what I've gathered static variables
remain the same variables with each instationation of a class. Meaning if
instation one of class YY sets static variable x to 1 and then five seconds
later instatiation two of class YY sets static variable x to 2, instation one's
variable x will get the value 2 as well. Is that correct?

2. Are there any other ways of getting back to the scope of the class besides
static variables?

Thanks again.

Best

stephan
LuigiL
1/11/2006 4:40:39 PM
1. Yes. A static variable is the same for all instances of the class. Which in this case isn't harmfull.
AddThis Social Bookmark Button