Best PracticesWhen to Use with


Best PracticesWhen to Use with

Normally 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();




Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net