Flash / AS

Blend / WPF
ASP.net / PHP

Photoshop

Forums
Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

The with() Statement
       by Kevin Kelly aka bear  |  3 March 2006

Often times, you will find yourself assigning many properties to one particular movie clip. Let's say you have a movie clip instance called theContent_txt. Adding properties to it could look like this:

theContent_txt.text = "the business is mine";
theContent_txt._x = 456;
theContent_txt._y = 345;

Notice how you are repeating the word theContent. A better, cleaner method for referencing one particular object would be to use the with() statement.

The with() statement calls an object once and allows you to access all of the object's properties and methods with only one reference. For example, using the with() statement, the above lines of code can be written as the following:

with(theContent_txt)
{
text = "the business is mine!";
_x =456;
_y =345;
}

I refer to theContent_txt only once! The with() statement may not be versatile enough to carry event handlers, but it does the work of referencing almost any class or object for you.

The following is an example of it working with the top level class Mouse:

with(Mouse)
{
hide();
}

In the above code snippet, I used a top level class and called its hide method.

You can also call nested objects inside the original object. Here is a diagram to better help you visualize what I am referring to:

The code for calling the secondObject object using with() would be:

with(firstObject)
{
secondObject._x = 340;
}

Here, I used a direct path to gain access to the properties of the nested secondObject object.


So, there you have it. This is my quick, short take on using the with() statement. Beyond simply providing aesthetic value to your code, it helps you to easily group together and recognize object assignments.

Thank you for your time. If you have any questions, please post them on the forum.

Kevin Kelly
http://kevink.ca

 


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components

Flash Templates
CSS Templates
Dreamweaver Templates

flash menus, buttons and components
Digicrafts Components The best flash components ever!
Entheos Flash Website Templates Free Flash Page Flip
flash components Buy and sell FLAs at Ultrashock!
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com create flash slideshow as easy as 1,2,3
Learn how to advertise on kirupa.com