Adobe Flex is a technology comprised from 3 fundamental elements:
- Languages – ActionScript & MXML
- Flex SDK
- Flex Builder IDE
This topic quickly introduces the languages, so in the end you’ll have enough conceptual knowledge to start experimenting with Flex and more importantly to make sense out of your trials.
ActionScript and MXML are introduced in parallel, thus it’s more easier to make analogies and comparisons between them.
The compilation process & Language fundamentals
We start with a short overview of the compilation process – how from MXML and ActionScript files you end up with a compiled SWF. And then briefly go through the languages fundamentals – classes and interfaces (MXML also defines a class), the package system (imports and XML namespaces), functions and anonymous functions, variables and constants, getters and setters, scope peculiarities.
MXML tags & special tags
Then, we look at MXML in further detail – what exactly is an MXML-tag, MXML special tags (described briefly, just to get you acquainted of what’s in the language).
Metadata tags
There’s a section in the slides dedicated to metadata tags (a.k.a. annotations), the most widely used metadata tags are described in further detail.
Events
Since they are a crucial concept to Flash, events deserve more attention. We are starting with exploring the IEventDispatcher interface. Then we look what’s in the Event-class and go through a detailed explanation of the event propagation mechanism.
Other features in the language
Features like exception handling, iterators, regular expressions and E4X are just mentioned without going into detail.
Data Binding
Our first experience with the Data Binding in Flex is focused on the user-perspective – how you declare and use data binding, without going into implementation details.
If you want to dive into the deep waters of Flex DataBinding don’t forget to take a look at these slides:
ActionScript vs. MXML
We end with comparing the two languages and answering the question “When should we use ActionScript and when should we use MXML?”
Pingback: The VMWare Flex Training Program - Obecto Training Portal
One interesting question arose while we were looking at the dynamic class modifier:
“Is there a typical case where I need to use the dynamic keyword?”
And while I was trying to answer this question, we end up discussing Type-safe vs. Dynamic programming languages.
The thing is that I’m still unable to find a case where we can’t live without dynamic classes. The dynamic keyword simply adds some dynamic programming capabilities into ActionScript 3.0. Such capabilities where quite common to ActionScript 2.0, but since ActionScript 3.0 is trying to solve a lot of performance issues the dynamism of the language was changed with a type-safety. But still the Object, the MovieClip, the TextField and others are kept dynamic.
You won’t regret if you check this really cool article on dynamic classes:
ActionScript 3: Dynamic classes
And another fun article in the same blog, but somewhat related to the topic above:
Adobe Flex: Program in Style or an Elevator Pitch
Having the capability to do stuff typical for the dynamic programming languages brings the questions:
“How am I supposed to exploit the productivity of the dynamic languages without making a complete mess?”
I believe a nice discussion about this you can find in the Bruce Eckel’s article Strong Typing vs. Strong Testing.
Another interesting discussion from yesterday was what do we do if we have to extend a functionality that is part of the mx_internal namespace? And as we all came to the agreement that you should have pretty good reasons to touch an mx_internal, the open question is:
How we are supposed to migrate to the next version of the Flex Framework?
Is there going to be some backward compatibility with Flex 3?
The migration from Flex 2 to Flex 3 was not that painful, since the changes between these versions wasn’t that drastic, as we expect it will be when we have to migrate to Flex 4.
I’ve tested the [ArrayElementType] metadata tag and I can conclude that it does almost nothing – no compile warnings, no run-time warnings or errors, no nothing… It seem so… but there is one case where it works. It works only in conjunction with [DefaultProperty] metadata tag:
TestArrayElementType.as
package test { [DefaultProperty("array")] public class TestArrayElementType { [ArrayElementType("test.SomeType")] public var array : Array = new Array(); } }app.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:Application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:test="test.*"> <test:TestArrayElementType> <!-- Here when we are adding array elements the Flex Builder code hinting will suggest us <test:SomeType... --> <test:SomeType/> <test:SomeType/> <test:AnotherType/> <!-- This line will give a compile error --> </test:TestArrayElementType> <test:TestArrayElementType> <test:array> <mx:Array> <test:SomeType/> <test:SomeType/> <test:AnotherType/> <!-- This line WILL NOT give a compile error (Go Figure) --> <mx:Array/> <test:array/> </test:TestArrayElementType> </mx:Application>Anyway it looks like the [ArrayElementType] metadata tag is poorly designed and very poorly documented.
Questions from today, if someone’s willing to dig into them:
1. What’s happening if we omit any class access modifiers from the class definition?
2. Is there some way to set the warning level of compilation, so warnings will prevent the application from execution, just as ordinary errors do?
The first Lab will start with some quick hands-on using ActionScript 3 with the following goals in mind:
1. Referencing AS3 library projects.
2. Understanding AS3 Reflection:
– getQualifiedClassName() (check documentation);
– getQualifiedSuperclassName() (check documentation);
– ApplicationDomain.currentDomain.getDefinition() (check documentation);
– describeType() (check documentation);
3. Hands-on experience with XML, E4X, and various AS3 constructs.
4. Compiling custom metadata tags.
The exercise projects are incomplete samples, in which you’ll need to fill in the missing functionallity:
DOWNLOAD EXERCISE AS3 LIBRARY PROJECT
DOWNLOAD EXERCISE FLEX PROJECT
If you want to see the completed projects:
DOWNLOAD COMPLETED AS3 LIBRARY PROJECT
DOWNLOAD COMPLETED FLEX PROJECT
The second Lab is designed to develop a further understanding of how the event mechanism is working – handling an event at all of its phases. You can also learn how to make a custom event, how to annotate a custom component with the [Event]-metadata tag, and how to stop the event’s propagation.
DOWNLOAD PROJECT
Group 6 Training Exercise 1:
DOWNLOAD LAB 01 LIBRARY PROJECT
DOWNLOAD LAB 01 PROJECT