Skip to content

with() Problem/Bug

Categories: Flash

Table of Contents

This is yet another bug I found while doing some Flash-dev, it has to do with the with() statement.
If you use with(this){…} it will give you erratic/unpredicted behavior, for instance take this code:

ob = {};
ob.test = function() {
	with(this) {
		__x = 1;
		trace("test: inside: "+__x);
	}
	
	trace("test: outside: "+this.__x);
}

ob.test();

You would think that output would look like this:

test: inside: 1
test: outside: 1

But, instead it comes out as:

test: inside: 1
test: outside: undefined

Seems as though Flash does not allow you to set variables when using this in a with() statement. You can get the .fla i used to make the test cases for this bug here.
Thanks Macromedia for wasting another hour of my time! 😛

Keep in Touch

Subscribe to my email list to keep in touch. I’ll send you new blog posts and other thoughts.