all groups > flash actionscript > october 2005 >
You're in the

flash actionscript

group:

classes and scope of variables and functions



Re: classes and scope of variables and functions *
10/14/2005 5:07:10 PM
flash actionscript: For your first question, try:

trace(this.HOTSPOT_AMOUNT);

And make certain that you're passing a Number for _hotspotamount.

For your second question, startNavigation should work when called from within
the Mapnavigator class but because it's private, you can't call it from outside
the class without a get or set function. If you want to use it outside of the
class you're going to have to declare it public.



On Fri, 14 Oct 2005 22:37:47 +0000 (UTC), "stephan.k"
[quoted text, click to view]
classes and scope of variables and functions stephan.k
10/14/2005 10:37:47 PM
Hi Everyone.

I am trying to wrap my head around the classes and the OOP concepts.

Please take a look at the code below. I tried to clean it up to the bare
essentials and I marked out the two main questions I ran into. They are marked
as comments next to the critical lines...

Any help or insight appreciated.

Thanks in advance.

sk.


-------------------


class com.maptraction.Mapnavigator {

private var HOTSPOT_AMOUNT:Number;
private var MAPPATH:MovieClip;

public function Mapnavigator(_mapName:MovieClip,_hotspotamount:Number){
MAPPATH = _mapName;
HOTSPOT_AMOUNT = _hotspotamount;
starter();
}




private function starter(){
MAPPATH.onEnterFrame = function(){
trace(HOTSPOT_AMOUNT) // >> undefined >> how do I get to the scope of
this variable?
startNavigation(rootpath,SCALE_FACT,ZOOMSPEED); //>> flash doesn't see
this function... why not? What do I need to do to access the function?
}
}

private function startNavigation(){
//navcode...
};
}


-----------------------------


Re: classes and scope of variables and functions stephan.k
10/15/2005 12:00:00 AM
Great. Got it!

Thank you very much.

Re: classes and scope of variables and functions LuigiL
10/15/2005 12:09:33 PM
Things don't run as expected because your in the scope chain of MAPPATH. You
need to set a local reference to the current class, see attached.



class com.maptraction.Mapnavigator {

private var HOTSPOT_AMOUNT:Number;
private var MAPPATH:MovieClip;

public function Mapnavigator(_mapName:MovieClip,_hotspotamount:Number){
MAPPATH = _root;
HOTSPOT_AMOUNT = 100;
starter();
}

private function starter(){
var thisObj:com.maptraction.Mapnavigator=this; // local reference to the
current object
MAPPATH.onEnterFrame = function(){
trace(thisObj.HOTSPOT_AMOUNT) // >> traces 100 now
thisObj.startNavigation(); //>> now the function gets called correctly
}
}

private function startNavigation(){
trace("startNavigation called!")
};
}
AddThis Social Bookmark Button