Recently, I learned about the with keyword in ActionScript 3. I've been programming in AS3 for more than six months by now but I've never seen that keyword used in any source code or book I've read. I saw it for the first time in Colin Mook's Essential ActionScript 3. It can be used to write cleaner code when setting multiple properties of the same object. For example, suppose you want to set some properties in a custom Event class before dispatching it. It may look something like this:
By using with it will look like that:
The second example is somehow cleaner and you don't need to type the name of the object everytime you set some of its properties. Of course it's not worth using it you are only setting few variables.var userEvent : UserEvent = new UserEvent( UserEvent.SET_INFO );
userEvent.age = 20;
userEvent.firstName = "Vladimir";
userEvent.lastName = "Angelov";
userEvent.friendsIds = [4, 3, 23, 6];
userEvent.description = "Some personal desc.";
userEvent.country = "Bulgaria";
dispatchEvent( userEvent ); var userEvent : UserEvent = new UserEvent( UserEvent.SET_INFO );
with( userEvent ) {
age = 20;
firstName = "Vladimir";
lastName = "Angelov";
friendsIds = [4, 3, 23, 6];
description = "Some personal desc.";
country = "Bulgaria";
}
dispatchEvent( userEvent );

I wanted to say how amazing the "with" keywork is. It's available in tons of OOP languages and saves so much time and energy.