avoid mickey mouse programming
solutions
Flex code annotations
Oct 14th
Today I was talking with a friend of mine that said to me that the only way to find something related to code annotations in Flex is a book he has… that’s definitely not true, the Flex documentation contain a lot of info on this topic and the web is full of resources.
In this short post I want to summarize the building blocks of code annotation in Flex.
In computing, the programmer often adds annotations to source code in the form of comments. These do not affect the working of the program but give explanations (for other programmers, or potential readers of the code principally, but also as a reminder for the author), hints or plans for improvement, etc.
Further Annotations can also be added by a compiler or programmer in the form of metadata, which is then made available in later stages of building or executing a program. For example, a compiler may use metadata to make decisions about what warnings to issue, or a linker can use metadata to connect multiple object files into a single executable.
In computer programming, a Java annotation is a way of adding metadata to Java source code that can also be available to the programmer at run-time.
Java annotations can be added to program elements such as classes, methods, fields, parameters, local variables, and packages.
Unlike tags added to Java documentation and processed with tools such as XDoclet, Java annotations are completely accessible to the programmer while the software is running using reflection.
Class annotations, also known as metadata in Flex, are extremely valuable as they allow developers to provide additional information about classes, properties and methods which may not be appropriate to convey through implementation details such as Marker interfaces or some other means.
You can create your own custom metadata following the same format. The example which follows defines a custom metadata attribute utilized for annotating a class with version information. The name of the annotation is “Version”, which contains three properties; major, minor and revision.
package{
[Version(major="1", minor="2", revision="123")]
public class Model {
}
}
Accessing custom annotations in Flex is accomplished via the flash.utils reflection APIs; describeType, getQualifiedClassName and getDefinitionByName.
ArrayElementType metadata tag can be easily associated to code annotations in fact when you define an Array variable in ActionScript, you specify Array as the data type of the variable but you cannot specify the data type of the elements of the Array.
To allow the Flex MXML compiler to perform type checking on Array elements, you can use the [ArrayElementType] metadata tag to specify the allowed data type of the Array elements, as the following example shows:
public class myComponent extends VBox {
[ArrayElementType("String")]
public var users:Array;
[ArrayElementType("Number")]
public var orders:Array;
}
In a more complex environment you can use java beans in Flex as the datatype of the ArrayElementType tag specifyng the fully qualified name of the class or get inspiration from this article http://www.flexpasta.com/index.php/2008/05/19/blazeds-with-annotations-for-remote-objects/ that is strictly related to Flex and Blaze DS (i.e. java based enterprise applications).
This tag only works for Arrays – there is no way to set the type of elements in ArrayCollection, to have typed array collection, you can take existing ArrayCollection.as rename it to YourArrayCollection.as and modify source property and add ArrayElementType tag with your prefered type, (I have not tried it but it should work) or even better extend the ArrayCollection in order to create your custom collection with the support for the ArrayElementType metatag.
In order to check the generated code add the -keep parameters to the flex builder compiler.
Update Framework for Adobe AIR Applications
Jun 25th
This beta release of the update framework for Adobe AIR Applications provides APIs to assist developers in including good update capabilities in their AIR applications. The functionality present in update framework assists developers in the following:
* Periodically checking for updates based on an interval or at the request of the user
* Downloading AIR files (updates) from a web source
* Alerting the user on the first run of the newly installed version or performing data migration
* Confirming that the user wants to check for updates
* Displaying information to the user on the new available version for download
* Displaying download progress and error information to the user
The update framework supplies a default user interface that your application can use. It provides the user with basic information and options related to application updates. Your application can also also define its own custom user interface for use with the update framework.
For more info chek this link.
Flex Google Analytics
Apr 18th
Sometimes you need to monitor your Flex application and get all the info dealing with the usage of the application.
Surfing the web I found this nice component.
Flex Google Analytics Magic component will now allow you to track all of your Flex Application activities through Google Analytics. The magic is that you only have to write one line of code in your Flex application to enable this if you use this component. The Flex Google Analytics Magic component will automatically track all user navigation clicks, button click, check boxes, radio buttons and a number of other controls within your app automatically.
Nice stuff!!!