Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-13-2003, 12:21 PM   #1
nicmar
Registered User
 
Join Date: Mar 2003
Posts: 66
Default Variables scope?

I have this in a function, called with animload(this).. although it produces the weird output, see below:

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

Quote:
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
nicmar is offline   Reply With Quote
Old 03-13-2003, 07:58 PM   #2
jaybee
Senior Citizen
 
jaybee's Avatar
 
Join Date: Feb 2003
Location: underneath the arches
Posts: 443
Default

I dunno but might you need the this keyword in there?
ActionScript Code:
origx = this._x;
jaybee is offline   Reply With Quote
Old 03-13-2003, 09:07 PM   #3
littleRichard
Registered User
 
littleRichard's Avatar
 
Join Date: Feb 2003
Location: Florida
Posts: 289
Default

ActionScript Code:
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.
littleRichard is offline   Reply With Quote
Old 03-14-2003, 06:04 AM   #4
nicmar
Registered User
 
Join Date: Mar 2003
Posts: 66
Default

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
nicmar is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:24 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.