Best PracticesWhen to Use withNormally it's best to avoid the with statement. However, it can help make your code more readable when you use the drawing API. For example, consider the following: this.attachMovie("myBox", "box", 1); myBox.lineStyle(1, 0x669999, 100); myBox.beginFill(0x336666, 80); myBox.moveTo(0,0); myBox.lineTo(100,0); myBox.lineTo(100,100); myBox.lineTo(0,100); myBox.lineTo(0,0); myBox.endFill(); Contrast that with the following: this.attachMovie("myBox", "box", 1); with (myBox){ lineStyle(1, 0x669999, 100); beginFill(0x336666, 80); moveTo(0,0); lineTo(100,0); lineTo(100,100); lineTo(0,100); lineTo(0,0); endFill(); } Another option for making this code more readable is to use a local variable (a variable whose scope is available only in the parent timeline) to refer to the new movie clip. Consider the following example: var b:MovieClip = this.attachMovie("myBox", "box", 1); b.lineStyle(1, 0x669999, 100); b.beginFill(0x336666, 80); b.moveTo(0,0); b.lineTo(100,0); b.lineTo(100,100); b.lineTo(0,100); b.lineTo(0,0); b.endFill(); |