Adobe Flex, what is this language similar to? - apache-flex

I recently heard about Adobe Flex. I am not sure what this programming language is. How can I use it in web development? For example, gilt taste by google uses HTML5, CSS3, and Adobe Flex. Forgive my ignorance, I only heard about this language yesterday.

Flex is a framework for flash. You can use the following languages in the Flex framework:
MXML
Actionscript 3
Css
Flex was created for making flash applications easier and faster since you can do a lot of things without being forced to use Actionscript 3.
For example, if you wanted to set the color of the border of a textfield, add the text "hello" and add it to the stage. This is how you would do it in Flash using Actionscript 3:
var yourTextfield:TextField = new TextField();
yourTextfield..border.fill.color.value = 0xff3300;
yourTextfield.text = "hello";
addChild(yourTextfield);
And here's how you do it in the Flex framework using MXML:
<s:TextArea text="hello" borderColor="#ff3300"/>

Ancide's answer covers the basics. But to answer the question a bit more ("similar to"), ActionScript is often compared to Java for it's similarities. (Although there are a few differences. IMO AS3 has some nice feature improvements over Java such as implicit getters/setters, a more flexible switch() statement, simple 'Function pointers'--for lack of a better term, functions can be easily passed as parameters--useful for implementing event handlers, and so on.)
MXML is similar to Microsoft WPF/Silverlight's XAML and is generally used for similar purposes.

Related

Is Adobe Flex all XML-based?

I am trying to develop an Android application and I heard that for someone with less-than-superior java skills, AIR/Flex might be a good place to start.
I am noticing that all I see in Flash Builder is MXML-based. Is this how all of the code in Flex written? Via XML?
It depends what you mean by "XML". MXML can contain chunks of ActionScript code both in blocks between <script> tags and right in line in attributes to controls tags, such as
<s:button click="someObject.DoSomething()">
This ActionScript embedded in MXML file is the pattern largely presented in the Flex in a Week series noted by #www-flextras-com.
But you can also have full, dedicated ActionScript files, both directly associated with .mxml objects and all by themselves. This "Code-Behind" design pattern is very much like the XAML design + C# code-behind combination in Windows Presentation Foundation applications.
An good introduction with a viewable example of strict code-behind in Flex :
Article
Browseable source code
Flex is a declarative, tag-based way of writing rich applications. Under the hood it is all ActionScript, though, so it is very easy to marry ActionScript code into a Flex application (as you often must do).
When I have coded with Flex, I use it as a declarative language. I use the tags to build out Views and data-driven containers. Then I write ActionScript classes to do all the imperative control logic. The relationship is similar to the one between JSP and Java, or (sort of) HTML and JavaScript.
In a nutshell though, yes, you can write whole Flex applications with its XML-like syntax and resort to ActionScript just to glue bits and pieces together, write small handler functions, etc.
This guy is a Flex genius and wrote a great book on it: http://dougmccune.com/blog/
HTH!
Flex is a mix of MXML and ActionScript. MXML is indeed XML based; but ActionScript is an ECMA compliant language. Conceptually similar to JavaScript.
I suggest you start by reading through the Flex docs to give you some background. The Flex in a Week tutorials come strongly recommended.

Beginner in Flex

Can i learn Flex with out learning ActionScript 3?
Learning Flex means learning both ActionSript 3 and Mxml languages, so in essence, you cannot learn Flex without learning ActionScript.
But if what you're really asking is whether you can learn Flex without prior ActionScript knowledge, then the answer is yes.
Why not try some introductory tutorials to help understand the framework? If you're familiar with other scripting languages then Actionscript shouldn't be too daunting.
Here are some decent tutorials to get started:
http://blog.theflashblog.com/?p=705
http://learn.adobe.com/wiki/display/Flex/Part+I.+Creating+a+Simple+RIA
I'd also recommend downloading "Tour de Flex" as a companion when getting started with the framework.
flex is gud, as i am flex developer, you can start learning flex, but you hav to learn actionscript too, b'coz at the end of day, i found myself working and coding in actionscript,
so flex eases the things, that wre much time taking in Actionscript,
like
Here you don't need to add the child hbox in the vbox, that's been done automatically, and do note that flex code is compiled in to AS code first, then that is converted to bytecode,before given to flash player to execute....so u r most welcome to the flex world , but do note AS is also imoprtant, and it's very intertesting,:-)
tc
Ankur
No, not really. To do anything remotely useful you'll need to be able to write some actionscript. You can easily do some layout, but mxml is really best for just creating views. If you want to just create a 'hello world' program, then you can certainly do that with flex. However, when you want to build something substantive you'll need actionscript. Also note that the mxml tags are all written in actionscript, so if you want to understand them under the hood, you'll also need to know actionscript.

what are the advantages of using mxml over actionscript in a flex application?

they both seem to accomplish the same things with different syntax, whats the point of using two different technologies. Please highlight every possible benefit of using mxml. Also are there scenarios when one is more beneficial than the other and why.
Please clarify this runtime behavior of mxml vs AS3 as discussed in Oreilly Flex 4 Cookbook page 1:
" Many newcomers to Flex wonder how MXML and ActionScript relate to one another.
The MXML compiler (mxmlc), after parsing through the different idioms, translates
them into the same objects, so that this:
<s:Button id="btn" label="My Button" height="100"/>
and this:
var btn:Button = new Button();
btn.label = "My Button";
btn.height = 100;
produce the same object. The major difference is that while creating that object in
ActionScript (the second example) creates the button and nothing else, creating the
object in MXML adds the button to whatever component contains the MXML code.
The Flex Framework handles calling the constructor of the object described in MXML
and either adding it to the parent or setting it as a property of the parent. "
Usually,
MXML is used to build the user interface
ActionScript is used to code the logic of your application
Of course, you can also build the user interface with ActionScript but :
it will take you more time
MXML views are easier to read than AS views
In terms of user interface, ActionScript should be used only to manage view elements (add, remove, ...) at runtime.
Edit
Within a Flex application, one is expected to favor using mxml over AS, provided both uses are available. In case mxml doesn't provide a solution , the user can fallback to AS3. Flex is a framework, therefore you would expect that the emphasis is put towards mxml, rather than AS3. Like most frameworks , the idea is to hide the details in order to facilitate design and supposedly make programming more accessible.
Everything comes at a cost though, you can't really expect mxml to be faster than AS3 since it's built on top of it. A logical conclusion would be to decide on a case basis. What are your app requirements, is there really a performance gain in using this component or not etc... Apart from the fact that Flex as a whole is bound to be slower than AS3, I don't think you can set general rules. One could add that if one is worried about performance, why choose Flex in the first place...
End of Edit
The Flex framework is geared towards building RIAs, therefore it comes with a bunch of components to that effect and mxml which mainly deals with the layout of these components, Actionscript being the language the Flex framework is built upon, will typically be used for the logic of your application.
The question is not really why choose one over the other. It's the same approach you would have if you decide to develop using a language directly or using a framework based on this language. It's like comparing JQuery & Javascript or CodeIgniter & PHP .I don't mean to imply that the reasons to use JQuery are the same regarding using Flex. Whilst JQuery will attempt to hide browser specificities and make JS more accessible , Flex's purpose is entirely different.
If you're developing RIAs, Flex makes sense, if you're developing games, not really. All you can do with Flex can be done with AS3 , only you wouldn't want to spend time developing DataGrids or HBoxes whilst you could spend more time on your app structure & design.
On the other hand, if you're developing a website or a game , you wouldn't want to add the weight of the Flex framework to your swf, simply because you've added a few Image components and a couple of Labels.
Flex is not adapted to every situation, unlike my previous Javascript or Php examples , Flex's purpose is not to make the language it's based upon more accessible or easier to deal with. Flex has a very specific target.
A similar question might be "what is the advantage of using HTML over Javascript for the UI?"
I suppose you are really asking "what is the advantage of using a declarative UI over an imperative one?"
Declarative UIs are more like configuration -- no logic (or in the case of MXML, very little logic). Declarative UIs separate the specification of the view from the behavior and data.
Tooling almost always prefers declarative UIs as well, because declarative specs tend to be extremely well suited to serialization... much easier for a tool to update MXML than ActionScript with properties and such.
As you get more familiar with the concept, declarative UIs start to feel more natural, and most people tend to prefer them.
Productivity, you create view elements with MXML faster than with AS3.
Under the surface MXML get's converted to the same AS3 bytecode as if you'd write in plain AS3 so the question if MXML makes the app slower comes down to how well the Flex compiler does the conversion.
As for the original question I would say that MXML is for visual development but as said before you hit the limits when trying to create custom components.
Personally I write Flex apps in 99.9% plain AS3 because I can't stand MXML. The only MXML file is the required Entry class so the compiler knows it should be a Flex app that it compiles.
Either way your app is going to get converted to an ActionScript object.
The advantage of using MXML is user friendly and more control on the look and feel of application. sometimes its easy to fix issues aligining your components on the right pane or panel with MXML.
The advantage i see using actionScript is command over your application, you have more control. Sometimes your MXML does not get you the itch of what you are looking and actionScript gives you more power.
I would suggest you to play with both to build an application which can give you less headache and better results.
None, Flex is for learning, as you learn more you use more .as and then one day... you use 0 Flex.
For one it's slow.
(edit - answer to comments)
'Why is flex slow' - it creates computer generated .as code. Equivalent functionality in .as is faster and smaller.
'MXML separates UI from code' - I'd say no it does not. First of ... it's XML.
If you are new, check out other frameworks, like Away3d, FDT and MinimalComponents. As you get more advanced, you use less MXML and one day no MXML, you are writing pure .as.
Anything in Flex can be done in HTML5/.js better. Also .as is much better than HTML5/.j
It's like a learning tricycle, and good for corporate developers that do drag and drop, they think of themselves as programmers. Software engineers... don't stay with Flex for long before evolving.
Here: http://www.youtube.com/watch?v=TL2t8eOs1XE
I feel sorry for you if you stay in Flex and don't advance.

What is the difference between Flex and Flash CS4?

What differences are there betwee Flash CS4 and Flex, besides the GUI of Flash?
"Flex" isn't the application, "Flex Builder" is. That's important - "Flex" is a framework. Asking the difference between Flash and Flex is a bit like asking the difference between JavaScript and JQuery.
Flex Builder is an eclipse-based code editor that has built-in support for the Flex framework. The Flex Framework gives you a powerful set of tools for working with data - these tools are generally speaking not available in Flash.
If you're doing something really complex that deals with dynamic data, it might be worth considering using Flex instead of straight up Flash.
It gets a little confusing, though - you can use Flex Builder as your ActionScript editor in a Flash project. In other words, you still have the .fla but you do your coding in Flex Builder instead of Flash. The reason many people do this is that Flex Builder provides a much more robust code editor. For instance, you'll get code hinting for custom classes - which is an enormous timesaver if you're building something even moderately complex.
I hope that helps! Both Flex Builder and Flash are powerful tools, I'd recommend playing with both of them to get a sense of what you can do with each.
Flex is a programming environment, with a proper programming IDE like you'd find for Java. It's focused on software development - the fact a Flex app is compiled to a Flash SWF binary is almost irrelevant.
Flash CS4 is an art/graphic design tool. It allows you to do some coding, but this is focused on tagging code onto animations. It's a bit like how you can do coding in MSAccess - it's allowed but not the main focus, and the development tools are not at all geared at coders. In fact you have to learn how to even find the code in CS4.
Bottom line, if you are a programmer then Flex will seem natural. CS4 won't.
Flash is more focused on animation (comes with a library, etc.) and Flex is focused on web application development.
A nice article covering Flash and Flex can be found here.

When should an oldschool flash developer use flex?

What are the key differences between Flash and Flex? I have over five years experience with flash and feel very comfortable developing with it and ActionScript3. I find myself more and more curious about Flex and want to know when it is best to use flash or flex. Also, is everything that can be done with MXML, able to be done with AS3? I have a strong understanding of AS3 and OOP and would like to know the diffrences between using AS3 and MXML in Flex.
Flex is great if you quickly want to build a UI, you can mock up a functioning UI in a couple hours. Since it still can be limiting for some custom UI's it's not perfect for everything but if something should "look" more or less like an application and fit in a grid it's super quick to mock up the UI in MXML. Also don't be intimidated of how most Flex apps look (ugly, imo), you can customize everything or easily create your own components.
Putting actionscript in mxml is the same as putting css or javascript in html = really bad. Unfortunately even Adobe has this in multiple examples (probably mostly because it's easier & faster for demostrations).. My personal opinion is that this applies to bindings too, as i don't want to put my data in the UI (mxml).
As an experienced developer I'm sure you don't do any development on the timeline (to clarify the Flash = timeline misconception). Still with Flex you have the UI separated in a framework that handles a lot of the burden with layout so that you can concentrate on the business logic. The rest of the workflow is close to what you probably already have with Flash.
It depends on what kind of applications you are developing now with Flash. I have been a Flash developer (mainly applications) for 7 years. I must honestly say that I was extremely glad when Flex 2 was released because it had the component framework (good components, layout managers, ...) I did not have in Flash. This is IMO the biggest difference between Flash and Flex (or the Flex framework).
MXML is a real blessing, especially when using data binding. In the end, everything is compiled down to ActionScript (check the -keep compiler option), but MXML just saves you so much time.
Flash and Flex provide different ways to produce different things. I am not familiar with Flash, but I would expect that it is dependent on a time-oriented way to produce something, whereas Flex is geared toward more traditional software development. That is, rather than dealing with time and frames in Flash, one is dealing with describing where components should be placed with MXML and how those components work with ActionScript.
One should also be able to write a Flex app with just AS3 and no need MXML.
The main difference between AS3 and MXML in Flex, as far as I know, is that MXML is not intended to be used with application logic, but rather it is intended to be used like HTML/CSS in web pages and puts components and content onto the Flex app. ActionScript is used to program behaviors, components, and other things outside or what MXML does. Thus, if you want to attach an event to a component one would write ActionScript code.
Hope that helps. I am still learning about Flex myself.
Some other differences that come to mind:
Flash allows you to create graphical assets and then work with them immediately. To use those same things in Flex, you need to use Flash to export them to a swf or swc first.
Flex has a layout manager, so applications that have variable window size are waaaay easier to make. For instance, you can take a window and set it to 90% width of the window, and it will change size... not scale mind you, but actually change its width as the window is made larger or smaller. This is not easy outside of the Flex framework.
Data Binding in Flex is a huge timesaver. It essentially creates all of the code you'd need to write in AS3 by simply saying blah="{foo}" The curley braces denote "bind to this".
The Flex Debugger is vastly superior to the Flash one. There is also a Profiler.
Since I started with Flex and not Flash, I'm not sure what kind of IDE is best for Flash dev, but the Eclipse based Flex Builder is quite nice. The code hinting is great. Subclipse integration is great.
Really, Flash and Flex are different beasts. You should know and understand AS3 if you want to use Flex, and since you do, you're in a perfect position to take advantage of Flex's features. Flash is not going anywhere as a tool for making more visually creative pieces, but Flex offers a lot of advantages for application development.
I prefer Flash IDE vs Flex (aka Flex Builder aka Flash Builder for my comment)
In general i would say it depends on the size of the project.
I find it easier to start and finish small projects quickly in Flash.
I would advise Flex for larger projects because it has various debug tools that can save you plenty of time (although i would still just use Flash my self)
But maybe if you really get used to flex, that might not matter.
some Cons of Flex from my experience.
When working on a team of 4 on a
large project, Flex failed to keep
the project
settings from one computer to another. (we shared files using SVN)
Flex constantly conflicted with SVN for us.
I felt distant from the art assets.
some Pros of Flex
being able to follow variable references from one class to another at the click of a button.
being able to easily see many variables while debugging. w/o needing to trace them.
and Flash used to not have Custom Class Code hinting, but now with CS5 it does.
I think you can use the newest features of Flash Player w/o waiting for a new Flash CS#, for example MoleHill (a new 3d api that uses the GPU) has a beta release out right now. and i think the Flex SDK can already use it.
hope this helps.
it should be noted that I am a rare case that doesn't prefer flex, most people strongly prefer flex, so you should give it a try at least.
MXML compiles to action script so it's really like a higher level version of that. So, yes, everything that can be done with MXML can be done with actionscript (but not the other way around).
Flash CSx:
GUI\Layout: Basic GUI class framework
Graphical Content: Great for editing graphical library objects with or without animation
Code: Lacks a good code editor
Flex/Flash Builder + Flex Framework:
GUI\Layout: Advanced GUI class framework and layout engine (Flex)
Graphical Content: Lacks drawing capabilities of Flash, but you can include Flash generated graphics by exporting them for ActionScript into a SWC and importing/referencing the SWC in Flash Builder.
Code: Much better code editor than Flash; not sure if it's on par with FlashDevelop
Other: Supports MXML, which is basically just another style of laying out content. Instead of writing a bunch of "c = new C()", "c.prop = x", "c.addChild"... you can structure display objects and thier children using XML constructs, and the MXML compiler will convert it all back into the less-readable, but basically the same AS3 code.
These technologies are all related and interoperable. They are natural and predictable extensions of the Flash player and ActionScript techonolgies, but for some reason Adobe developed the Flex/Flex-builder/MXML technologies as a totally separate product, and market it as something totally new and oh-so-amazing. Whatever. So now we have to go back and forth between the two to use all the features, which is LAME. They also have to waste time and resources developing unnecessary, but helpful, packages like the "Flex Component Kit" to reduce the number of steps necessary to get Flash content into Flash Builder.
You have to go back and forth between these applications, because of their mutually exclusive features -- Flash Builder lacks graphics editing, and Flash CSx lacks MXML and a good code editor -- but they're interoperable in the sense that you can use Flex classes in Flash, Flash classes (and their embedded graphics) in Flex, you can use Flash Builder and MXML without Flex, etc.
I think they need a single, truly integrated Flash IDE, so they need to merge Flash Builder into the Flash CSx editor.

Resources