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

flash actionscript

group:

Interesting scope issue/Function reference


Interesting scope issue/Function reference ufitzi
11/18/2004 9:23:43 PM
flash actionscript:
I'm experiencing an interesting effect I think relates to scope, yet cannot be
completely explained by it.
Here goes:

I am attempting to pass a method of Object1 to the constructor of Object2.
Object2 is basically a wrapper for the LoadVars class, and within the
constructor I define the LoadVars.onLoad event handler.
The major course of action taken by the onLoad() handler is to call the method
of Object1 that I passed as an arg to Object2.
It seems to work...YEAH!
I am able to trace() the resulting variables that I pass to the method of
Object1 from within that method, and they are the correct values.
I modify vars as needed and then move on in the app, attempting to use those
variables.
But when I attempt to access them, they are "undefined"
I know this sounds like a timing issue, but I have taken great care to wait
until the vars are available before attempting to access them.
Has anyone experienced anything like this?

My temp. solution has been to call Object1.method() directly, instead of
passing it as an arg.
Everything works now!
The problem I face is that I need "Object1.method()" to be different each time
I create and use an Object2.

Any ideas or discussion would be greatly appreciated!
Thanks, folks!
Re: Interesting scope issue/Function reference katieluv
11/18/2004 10:05:37 PM
Hmm you say you want Object1 to be different each time you instantiate an
instance of Object2, but yet from the description you are trying to store
persistent data irrespective of Object2's existance. I will thow out an idea
and maybe you can clarify your requirements some more from what I describe. If
you are trying to keep data persistent even if Object2 is removed and
reinstantiated, create a 'global' object at root level and use that to store
values. For example: globalVars.as - class globalVars { var property1:Number;}
Then instantiate the object in the first frame of root with - _root.global =
new globalVars(); and you can then reference the properties from any object
with _root.global.property1 = 123; Of course this is all untested. - Katie
Re: Interesting scope issue/Function reference ufitzi
11/29/2004 8:11:21 PM
Actually, Object 1 could be 1 of many objects that can "use" Object2.
Like an interface, except I haven't defined that interface yet!
What I need to do is pass some method of Object1 to the constructor of Object2.
Object2 sends and receives data, then invokes whatever method I pass to the
constructor.
The idea is that I will pass a different method to Object2 depending on the
type of data I am working with.
The actual reference to the function I pass seems to work.
I am able to call it from within Object2 like so :
this.functionName(args);
The function gets called, and I can even access the variables I pass to it.
But once I use them to set other variables (memebrs of Object1) and try to
trace those members, they are "undefined"
Very strange!!
Unless Flash is making a reference to those variables instead of using their
values, which in that case they would be undefined after Object2 is Destructed.
HMMMMM>>>>>>>>
AddThis Social Bookmark Button