Flex vs ActionScript - apache-flex

I'm trying to build/implement a Flash video player to play videos. I have looked at Flex and built a basic application with just a VideoElement. It gets compiled to 41k without statically linking the libs and 300k with linking the libs. I generated the report but am still not sure why I would need all those components just to build a VideoPlayer.
On the other hand, I have had a look at some implementations in ActionScript and it's compiled to 10K. Why is the file size so different in Flex than in pure ActionScript when they both compile down to swfs? Perhaps I'm confused by what Flex is so an explanation would help too. Thanks!

Flex is essentially a library of classes built on top of plain ActionScript (the mxml files even get generated into ActionScript classes at compile time), so in a nutshell the overhead you are seeing is due to dependencies within the Flex framework. Many people will try to create such things as video players in pure ActionScript to avoid these dependencies and keep the file size down.

Related

Flex classes in Pure AS3 projects

According to this blog article , some Flex components such as the Flex WebService and HTTPService don't rely on the Flex framework, so it should be possible to import and use them in a pure AS3 project.
I often wonder if Adobe could have designed Flex with a modular approach similar to that of the Zend framework, whereby some of the classes could have been imported without having to load the full framework.
Do you know of any other Flex components/classes that could be used in such a way?
The Flex Compiler--which is used in pure ActionScript projects compiled w/ Flash Builder--will optimize itself. Only the classes you use go into the final SWF. So, the final file size will no be affected if you put 100 classes in your library path and never use them. So, feel free to add the Flex SWC information and just use the HTTPService and/or WebService.
I would assume if you are using Flash Pro that similar optimizations occur when creating the final SWF.
That said, Adobe does seem to be moving in the direction of separating out Flex. Flex 4 classes, for example, are located across 10 different SWCs. Mobile classes in Flex Hero are also isolated, adding at least one more SWC to the mix.
I suggest you take a look at the rpc.swc class, as I guess that is where the HTTPService and other related classes reside.
The Text Layout Framework and OSMF are also part of the Flex framework but could be used in a pure AS3 project

What is the benefit of using Flex?

Since Flex generates Actionscript.
Why not use Actionscript at all ?!
sorry, i'm just curious .
I agree with the points made about Flex being for developers and Flash being for designers, but that doesn't really cover what is going on in detail.
There are three main ways to produce a Flash application (SWF):
1) Using the Flash application - the timeline approach, mainly aimed at designers.
2) Writing pure ActionScript directly and compiling (either through an IDE such as FlashBuilder or from the command line), aimed at programmers with creative flare or designers who don't mind getting their hands dirty.
3) Writing 'Flex' - usually using an IDE such as FlashBuilder, but yes you can compile your Flex application on the command line. Flex is MXML (an XML markup) and ActionScript. As stated, Flex is aimed at software developers, typically those who have less focus on the 'creative' side (delegating this responsibility elsewhere, e.g. a visual designer).
There's a big difference between #2 and #3 though.
ActionScript is great for programmers who want to do highly interactive and graphical Flash application, for instance, some interactive demo or a game perhaps. To create a Flash app via ActionScript you would create an ActionScript file, add the meta data to indicate it is an application and the compiler will generate an appropriate and usually very small SWF file. There are some components available at the pure ActionScript level, but these are very lightweight compared to Flex and most of the work is done by manipulating Sprite objects.
Flex does a lot more. It gives the developer a rich suite of skinnable components with which to build applications, a component lifecycle, effects and data bindings to name a few things. I would say that Flex is more for rich applications for some business domain, typically in the format of a form based application, though you can do some very sexy things with it and can pull in resources created elsewhere (e.g. existing Flash resources).
A Flex application has a top level 'Application' object which is an MXML file containing a hierarchy of components. At compile/build time this MXML file is converted to ActionScript (lots of it! there is a compiler flag which keeps the generated ActionScript, see the docs for more info) which is ultimately compiled in to a SWF that can run in Flash Player.
For instance, you would add Labels, TextInputs, Buttons and so on to a Panel and add the Panel to the application. The user interacts with these components, and then the Flash app processes the input in some way and updates the view. Data binding allows you to mark an object as 'bindable' and then have Flex automatically update some other property when the bindable property changes.
Flex applications tend to generate larger SWFs, but that is because they are carrying the 'baggage' of the Flex SDK, though this can be mitigated using runtime shared libraries (a bit like DLLs for Flash, but is an advanced topic) or Modules, which are SWFs that will only run inside of a Flex application and not standalone. But the idea is that the application is loaded in to the client and is responsive without having to perform page-requests as in a traditional web application. The perception of loading time is improved by breaking your application up in to modules or using runtime shared libraries as mentioned above.
To be honest, I'm not doing Flex justice with my description, but hopefully I have made the differences much clearer.
Flex does not generate ActionScript. Flex compiles ActionScript.
At any rate, Flex is Flash programming aimed at developers (who don't necessarily like having timline-based vector editor as the main development environment).
Also, since Flex is a console application, you can include its functionality in shell scripts etc etc.
I think a rhetorical question best answers this:
Why not use raw machine code for all projects?
In more detail, the Flex Framework is indeed written in pure actionscript. It offers substantially more than actionscript alone, and like most frameworks, addresses a need for higher level programming constructs that are not offered by the language that they are written in.
Adobe Flex and Adobe Flash differs in only one thing:
According to Adobe: "Adobe Flash is for designers, Adobe Flex is for developers. Flex is released for developers who do not feel comfortable with timeline stuff. "
Adobe Flash is a powerful tool; however,
as more programmers became involved in
building Rich Internet Applications,
it quickly became clear that they were
not comfortable using drawing tools,
timeline and other visual panels to
create forms and other elements that
are common to the business
application.
Adobe Flex was created to solve this
problem for programmers.
See this video: http://www.adobe.com/devnet/flex/videotraining/xml/vid01.html
If you feel comfortable with timelines (i am not) then there is no difference at all. You can use Adobe Flash.
The Flex framework allows developers to write applications more rapidly than writing pure ActionScript. Flex is written in MXML, which is a 'convenience language' and has a lot of pre-built components for writing business applications.
However if your goal is for creative purposes only, Flash would be a better tool for the job. But if you're asking between AS3 and Flex, I presume you're not tweening things in a timeline, as you would in Flash.
If you start using Flex, you will find that you must know ActionScript to give your app functionality that's not provided out of the box. Also, knowing ActionScript will be beneficial to both Flex and Flash worlds (and you can also write pure AS3 apps as well, but very few folks do that in my experience).

what tools are there to decompile swfs to flex

How can you know that an swf was written using flash or flex?
and is there a way to compile back to flex?
I know sothink's for flash, but any thing for flex?
A Flex app is fundamentally a Flash SWF - the only difference is that the flex compiler generates a lot of intermediate code (that you can see if you use -keep compiler option) and converts that code (instead of your mxml code) to SWF.
So I guess when you decompile a flex application with whatever tool you use to decompile a flash SWF, you will get only this generated code (and not your mxml) - which may or may not be helpful - it depends on your requirement.
Just googled to find that Sothink SWF Decompiler V5.2 supports SWF to Flex
Sothink SWF Decompiler and Eltima FlashDecompiler both reportedly support Flex decompilation. I have used Sothink's solution a few times to help in security audits and hand optimizing the byte code and when decompiled the result was about what you can expect out of any flash decompiler.
Exporting to flex provides a flex project that can not usually be recompiled without hand editing your files. However much of the original project does stay relatively close to the source (stripped variable names, multi stage variable assignment, etc.) and is nothing you can't fix if you're familiar with the source code. Which I assume you are, unless of course you're sneaking peeks at others livelihoods.
With that being said, for those of you who are unaware of flash security issues or have an interest in protecting your assets, Prajakta Jagdale at HP recently did a talk on flash decompilation at ShmooCon this year that is rather engaging. The video is available online if you're interested, but I'll leave finding that one as an exercise for the reader.

Flex(mx package) classes in Actionscript only project?

Can anyone tell me what is and isn't recommended when it comes to mixing in classes from the mx package in an Actionscript only project?
Specifically I want to use AsyncToken, IResponder and HTTPService classes in the mx package in an Actionscript project.
I guess the mixing problem comes when you need to use mx.* classes, but you're on a pure as3 project.
If it's as3, you can still make an actionscript flex project, using the framework.
When it comes to Flash, you can either export a SWC with your actionscript exported (linkage setup) and add that to your flex project.
Again, if your project weighs more on the flex framework than on flash, you might find the Component Kit handy.
But if it's a Flash IDE more oriented project ( as in simple data coming in, mostly design work, not much nerdy stuff to it ), using a few mx.* classes, just for the HTTP service, doesn't make much sense. The problem comes with the fact that flex is a framework, therefore things rely on each other to work well, like a brick tower...brick upon brick, upon brick...
and since it's code you're working with, things are somewhat dynamic, but still not much cement...so you might end up wasting more time finding all the flex dependencies and getting them to work outside the medium they were made for, rather then building some of the functionality by hand.
If you need an as3 only implementation for WebService, Carlo Alducente has one.
HTH
The non-visual mx classes should work fine in a AS3 only project. But they have a lot of dependencies so you SWF will be bloated.

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