PDA

View Full Version : Variables scope?


nicmar
03-13-2003, 12:21 PM
I have this in a function, called with animload(this).. although it produces the weird output, see below:


function animload(obj) {
with (obj) {
origx = _x; tox = _x;
origy = _y; toy = _y;
origa = _alpha; toa = _alpha;
trace(origx);
}
trace(obj);
trace(obj.origx);
}



197.1
_level0.gr
undefined


Why can't I get the variable origx from the object "obj" from outside the with function..?

I though that these were the same:

with (obj) { origx = 100; }
obj.origx = 100;

What is the difference??

Thanks in advance :)

jaybee
03-13-2003, 07:58 PM
I dunno but might you need the this keyword in there?

origx = this._x;

:confused:

littleRichard
03-13-2003, 09:07 PM
this.createEmptyMovieClip("someClip", 100);
this.someClip.origx = null;

this.animload(this.someClip);

function animload(obj) {
with (obj) {
origx = _x; tox = _x;
origy = _y; toy = _y;
origa = _alpha; toa = _alpha;
trace(origx);
}
trace(obj);
trace(obj.origx);
}


it looks like declaring a variable inside a with statement dosn't work. if "origx" isn't already defined in "obj" it gets created at _level0. if it is defined then the assignment works.

nicmar
03-14-2003, 06:04 AM
That is weird.. cause a variable set in the with statement can be read from another with statement... but I just don't get where it's strored... in the object, but in another level or something..

I need some experts on this maybe.. for now i soved the problem with:

obj.origx = blabla...

The source gets just a bit bigger, but I guess that's ok..

Thanks anyhow guys :)