With() doesn

(crap, hit return to soon… topic doesn’t make sense now :P)

Why won’t this work?

[AS]
_global.MyObject = new Object();

with(MyObject) {
FirstName = “Oscar”;
LastName = “Griffioen”;
}
[/AS]

For some reason the WITH clause doesn’t seem to work on my newly created object. How come?

try with(_global.MyObject)

:slight_smile:

*Originally posted by Syko *
try with(_global.MyObject)

This is why: When you define a _global object, you need to use _global everytime you refer to it, I thought. Not 100% sure though. :slight_smile: http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary379.html

you should also look up with.
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary826.html

note the phrase

To set a variable inside a with action, the variable must have been declared outside the with action or you must enter the full path to the Timeline on which you want the variable to live.

and yes, setting or changing _global properties requires the _global identifier. Referencing global values does not.

also see:
http://proto.layer51.com/d.aspx?f=1034
http://proto.layer51.com/d.aspx?f=885

*Originally posted by senocular *
**and yes, setting or changing _global properties requires the _global identifier. Referencing global values does not. **

… Right. Thanks for clearing that up for me sen =)

:slight_smile:

theres also a couple of _globl links in the Best of Senocular sticky in the actionscript forum