tags:

views:

333

answers:

2

It's possible within a Flex application, to declare elements, for example a HTTPService elements, both in XML and also in code.

That is, either: ...

or in code: var hs : HTTPService = ...

My question is when should I prefer which alternative? What are the advantages of having stuff in XML vs. plain old vars in code?

A: 

Elements are more concise and compact than AS3 code, tho of course ultimately it all becomes the same thing. You can, for example in 'one line' of mxml declare an HTTPService and set several of its properties. In script you'd need to do this in many lines of init code. If you have a lot of global variables this can start to become unruly.

Scott Evernden
+1  A: 

MXML is great for doing declarative layouts, much easier to follow than doing everything programmatically in ActionScript. If you are using something like a ServiceLocator to define HTTPService, RemoteObject, etc in your app then declaring them via MXML is also quick and easy. Basically if you want to add anything to an object's displayList quickly and easily, MXML is a great way.

cliff.meyers