all groups > flash actionscript > march 2006 >
You're in the

flash actionscript

group:

accessing var defined in function


accessing var defined in function abeall
3/31/2006 8:54:43 PM
flash actionscript:
In this case...:
function myFunc(){
var myVar;
myOtherFunc();
}
function myOtherFunc(){
//access to myVar?
}

...is it possible to edit myVar from myOtherFunc? If I had built myself the 3k
lines of code I'm dealing with I would have avoided this in the first
place(myVar being handed all over the place instead of a _root var or
something), but I'm looking for a quick fix that fits the current logic.

I tried arguments.caller.myVar, but that didn't work. Is there any way?

Thanks.
Re: accessing var defined in function TiJayOldroyd
3/31/2006 9:08:29 PM
Re: accessing var defined in function abeall
3/31/2006 9:40:11 PM
Thanks for the response

[quoted text, click to view]
symbol it was created in...
Actually, when you define a variable in a function, it is indeed local to that
function, not the timeline it's on. By using the var syntax it is ensuring it
is local. If I used this. it would be placed on the timeline. If I had used no
prefix, it could have been either depending on wether it already exists on the
timeline or not.

So my problem is the very fact that the var is not on the timeline, but rather
defined local to the function. I need to access the functions local var from
another function called with that function... like I said, I'm dealing with
several thousand lines of code that I didn't write, so I'm hesitent to try and
change the scope of an important variable from local to timeline, but it looks
like that's what I have to do.
Re: accessing var defined in function kglad
4/1/2006 1:43:17 AM
Re: accessing var defined in function abeall
4/1/2006 4:29:55 AM
Yeah... the problem is that there are lots of calling functions, and currently
the problematic function does not return anything so the caller functions
aren't really set up to handle a returned variable very well.

The issue with making myVar timeline is that it's also used as an argument in
various places, so that would potentially throw some stuff off. I ended up just
making an intermediate timeline variable (ick), since really it will only take
affect in a few places.
AddThis Social Bookmark Button