19 Replies Latest reply on Jan 6, 2010 11:12 PM by GordonSmith

    Is there an ActionScript reference for Flex?

    Dean Schulze

      I'm developing a Flex application using ActionScript instead of mxml.  Adobe's docs pretty much only show examples in mxml and there's no straight forward way to convert from mxml attributes to ActionScript properties (e.g. there's no equivalent ActionScript property for the mxml verticalAlign attribute for the VBox class).

       

      Is there an ActionScript reference for Flex?

       

      Thanks.

        • 1. Re: Is there an ActionScript reference for Flex?
          Flex harUI Adobe Employee

          Actionscript Language Reference http://livedocs.adobe.com/flex/3/langref/index.html

           

          Some properties are styles.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Is there an ActionScript reference for Flex?
            Dean Schulze Level 1

            Alex,

             

            If you actually look at those docs you'll see that the example code they give is mxml, not ActionScript.

             

            I have Adobes docs and I wouldn't have posted this question if I just needed a pointer to what I already have.

             

            Is there an ActionScript reference for Flex?  The mxml given in Adobe's docs is little use when you are writing ActionScript.

            • 4. Re: Is there an ActionScript reference for Flex?
              Dean Schulze Level 1

              They don't give you a clue how to use the Flex classes from ActionScript.

              • 5. Re: Is there an ActionScript reference for Flex?
                pauland Level 4

                Dean Schulze wrote:

                 

                They don't give you a clue how to use the Flex classes from ActionScript.

                 

                 

                They have examples. Those class definitions are the same as the MXML - the MXML tags compile to actionscript that uses those classes. The tags are based on those classes.

                • 6. Re: Is there an ActionScript reference for Flex?
                  Flex harUI Adobe Employee

                  There should be some AS examples in the livedocs.  Maybe start with the creating custom components chapter.

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui

                  • 7. Re: Is there an ActionScript reference for Flex?
                    Dean Schulze Level 1

                    Well, no.

                     

                    Try and set the vericalAlign property from the VBox class in ActionScript.

                     

                    Things like this are where an ActionScript reference is needed.

                    • 8. Re: Is there an ActionScript reference for Flex?
                      David_F57 Level 5

                      Hi Dean,

                       

                      I know that the reference guides can be somewhat intimidating sometimes but perseverance is the first thing you learn to deal with when it comes to the "help" system for flex, in some respects its getting better, personally my reference guide is called google it seems that sometimes it finds information in the Flex live references faster than the built in search engine.

                       

                      At the end of the day every thing you need to know about actionscript with mxml components is there. The best reference you have is actually installed with flashbuilder, its the sdk source.

                       

                      Every capability of any mxml component is exposed all you need to do is open up the source of the component you are interested in, Do this once or twice and suddenly questions like "what about vertical alignment in a vbox" become clear.

                       

                      this.setStyle("verticalAlign","middle");  (this being a vbox class)

                       

                      Flashbuilder/SDK is moving forward at a rapid rate of knots, the documentation tends to play catchup with that(and developers have trouble spelling documentation, let alone writing that stuff). Never the less the existing documentation does explain in most cases about properties that are set by style.

                       

                      Its more difficult for those that have only just started using flashbuilder as they have missed mountains of discussion on changes to properties and styles as the sdk and ide evolve.

                       

                      In the meantime you have a great adobe crew who do put a lot of time into addressing the concerns of those that run into trouble or need things clarified for them.

                       

                      Usually if you have a problem ask in these forums the odds are that you will have an answer faster than you would get spending hours googling for solutions.

                       

                       

                      David.

                       

                       

                      • 9. Re: Is there an ActionScript reference for Flex?
                        Dean Schulze Level 1

                        David,

                         

                        The docs aren't intimidating, but they do have the problem of ignoring OO programming in ActionScript.

                         

                        I'd love to be able to peruse the Flex ActionScript source, but I can't find it in my installation.  I've looked under

                         

                            C:\bin\Adobe\AdobeFlashBuilderBeta2\sdks\4.0.0

                         

                        but can't find any source.  Is it somewhere else?

                         

                        One serious problem with the docs is that if you don't scroll through them and click all of the "Open inherited ..." links you can't search in it effectively.  Open the doc for VBox and search (using Ctrl+F in your browser) for verticalAlign.  You won't find it unless you open the correct link first.

                         

                        Another serious problem is that if you use the Search function provided (not the browser Ctrl+F) and search for verticalAlign the results don't include VBox.  You have to know what the inheritance hierarchy for VBox is and recognize that what you want is in the docs for the Box class.

                         

                        The docs need to go back to the drawing board and be re-architected for usability, and to support ActionScript.

                         

                        It's beyond me why Adobe promotes using markup instead of OO programming using ActionScript.

                         

                        Google is great, but when it comes to Flex the number of returned hits is too large to be effective.  Most of what comes back is mxml.

                         

                        ActionScript is a nice little OO language, and Flex has much going for it, but I shouldn't have to resort to Google for a help system.

                        • 10. Re: Is there an ActionScript reference for Flex?
                          Muzak Level 3
                          It's beyond me why Adobe promotes using markup instead of OO programming using ActionScript.

                           

                          What makes you think OO is limited to ActionScript? MXML = Actionscript done differently..

                           

                          Another serious problem is that if you use the Search function provided (not the browser Ctrl+F) and search for verticalAlign the results don't include VBox.  You have to know what the inheritance hierarchy for VBox is and recognize that what you want is in the docs for the Box class.

                           

                          If you look at the top of the Box page (after having searched for verticalAlign) it says which classes it inherits from and which classes extend it (SubClasses). VBox is listed there..

                           

                          In FB3, VBox is listed in the search results by the way, allthough further down the result list, but that's because they're listed alphabetically if I'm not mistaken.

                          • 11. Re: Is there an ActionScript reference for Flex?
                            David_F57 Level 5

                            Hi,

                             

                            C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.0.0\frameworks\projects\framework\src\mx\containers

                             

                            the last entry in this folder is vbox.as --  I think the as stands for actionscript

                             

                             

                            I merely mentioned google as it returns exactly what the built in help search returns (well not the brand new system but close enough), it was probably more a dig at the slowness of flashbuilder search etc...

                             

                            As I stated the help system isn't the greatest but it is getting better. If intimidating isn't the right word may be frustrating is better description, override that with patience and the answers are there.

                             

                            Flashbuilder's mxml is just that a markup for the visual elements, just like most modern development, the 'gui' is descriptive and the functionality is provided through scripting/language.

                             

                            The fact that flashbuilder is designed around rapid application development is probably the reason the bulk of documentation appears to be biased towards mxml,

                             

                            <mx:vbox id="vb" x="10" y="10" width="100" height="200" verticalAlign="middle" mouseOver="vb_mouseOverHandlerr(event)"/> is very easy to do when code hinting helps you all the way. And so much better than

                             

                            var vb:VBox = new VBox();

                            vb.x=10;

                            vb.y=10;

                            vb.width=100;

                            vb.height=200;

                            vb.setStyle("verticalAlign","middle");

                            vb.addEventListener(MouseEvent.MOUSE_OVER,vb_mouseOverHandler);

                            parentcontainer.addChild(vb);

                             

                            I love digging into the coding side of things but I still enjoy the benefits that RAD has to offer. If doing it all in actionscript tickles your fancy so be it but there is no benefit doing it that way, pure actionscripting should be reserved for functionality or areas where the mxml option isn't viable, if you are using visual elements then go with mxml and use flashbuilder the way it was meant to be used.

                             

                            As for actionscript and google - things like "actionscript vBox" will give you everything you will ever need to know about vbox in the first 20 hits.

                             

                            Most of the time those actionscript examples do lead to an mxml application that uses the actionscript code but again thats what flashbuilder is all about, If you want pure actionscript based projects there are plenty of examples on how to do that in flashbuilder as well, one thing though its a wasted effort because if you use flex sdk components the flex sdk is still needed so no benefit is derived.

                             

                            So take a deep breath let flashbuilder evolve, make suggestions about what you feel needs improving in the help system, even log enhancement requests, the adobe guys don't ignore feedback they recieve.

                             

                            David.

                            • 12. Re: Is there an ActionScript reference for Flex?
                              Dean Schulze Level 1

                              Muzak,

                               

                              You can't do procedural programming - let alone OO programming - in mxml.  It is markup, not a programming language.  That is why all but the simplest mxml files have ActionScript embedded in them.  And those mxml files with embedded ActionScript get long and ugly.  They are hard to read and hard to maintain.

                               

                              They are almost as bad as JSPs, which is probably the worst Java-based technology ever.

                               

                              ActionScript, on the other hand lends itself to to clean organization of code, good encapsulation and good abstractions.

                              • 13. Re: Is there an ActionScript reference for Flex?
                                pauland Level 4

                                Dean, you can do just about anything in MXML that you can do in actionscript alone, so I don't agree with your views about MXML or indeed JSPs..

                                • 14. Re: Is there an ActionScript reference for Flex?
                                  David_F57 Level 5

                                  Hi Guys,

                                   

                                  To me once the academics got into terminology with the "design patterns" "MVC" etc...., and Britney spears turn OOPS into small package in tight leather, the true meaning  OOP got lost. It has nothing to do with design it's about the encapsulation of code and data(object) and of course you can do that in mxml, everything you do with actionscript, which happens to be wrapped as a package, can be done in mxml you just wrap it differently.

                                   

                                  There is nothing wrong with the purist view of gui/code being separated, and yes its cleaner. I had my concerns very early on with the lack of separation between layout(markup) and functionality but I realised if the developer isn't taking care of the structure themselves they should be in a field that doesn't require reasonable intelligence.

                                   

                                  For quick proto-typing straight mxml is wonderful and the advantage is you don't throw away the proto-type you just clean it up.

                                   

                                  So bottom line there is only 2 type of applications, functional and non-functional,  I'd rather a slightly messy source that works than a politically correct jumble of dysfunctionality.

                                   

                                  my 2 cents worth

                                   

                                  David.

                                  • 15. Re: Is there an ActionScript reference for Flex?
                                    Dean Schulze Level 1

                                    If you can do in mxml what you can do in ActionScript you wouldn't see that almost every non-trivial mxml file has ActionScript embedded.  Just try doing event handling in mxml.

                                     

                                    On the other hand ActionScript does not need mxml at all.

                                     

                                    From what I can find in various Flex books and posts the mxml programming model was created to make html authors comfortable with Flex development (html & Javascript analogous to mxml & ActionScript).

                                     

                                    I can't find any redeeming virtues in mxml, not even the RAD argument.

                                     

                                    However, if you like JSPs then I'm not surprised that you thing mxml is a good thing.  It's not as bad as JSP.

                                    • 16. Re: Is there an ActionScript reference for Flex?
                                      tinylion_uk Level 2

                                      Dean, you are correct, you don’t need mxml at all to use flex, and the asdoc is all you need i've written as projects with flex and asdocs has every bit of info you need.

                                       

                                      BUT, not giving mxml a chance means youre missing a trick, why not use it? I disagree that mxml is just some sort of poor mans easy intro to programming flex. You're missing the value it gives you in just getting the job done. Like anything else mxml needs to be used with skill and a deep understanding of what it is your doing, otherwise no matter what language you use you'll end up with non optimal code. I've been in software development for 25 years now starting with assembler development which i always loved for it's complete control over the project, so i understand a desire for some form of purity. I just think you need to make the BEST use of the best tools available to get the project completed. With Flex the best way and most efficient way to work is imho mxml/as3.

                                       

                                      Used correctly and with understanding there's isn’t an argument you could make against mxml/as3 together for flex development.

                                       

                                       

                                       

                                       

                                       

                                       

                                      tinylion development & design

                                      • 17. Re: Is there an ActionScript reference for Flex?
                                        GordonSmith Level 4

                                        We designed MXML for the same reason that Microsoft designed XAML, and for the same reason that Tim Berners-Lee designed HTML: Many developers find that declarative languages make it easier to implement user interfaces than procedural languages do. But if you don't like it, don't use it. It's hard to write the Application subclass itself in ActionScript, because of certain compiler magic that I wish didn't exist, but you don't have to use MXML for any component if you don't like MXML.

                                         

                                        The ASDoc reference is intended for developers programming in either ActionScript or MXML Your initial confusion was over the difference between a "property" and a "style". MXML makes them look the same, but they are very different in ActionScript, and it isn't the purpose of the ASDoc reference to explain the difference; that's covered elsewhere. But once you understand that in ActionScript you call setStyle() to set a style and addEventListener() to add an event listener, the ASDoc is extremely useful even if you aren't using MXML.

                                         

                                        As for the examples in the ASDoc... it's true that we favor using MXML+ActionScript in them, because the majority of Flex developers find that this combination makes them more productive than using pure ActionScript.

                                         

                                        Gordon Smith

                                        Adobe Flex SDK Team

                                        • 18. Re: Is there an ActionScript reference for Flex?
                                          Dean Schulze Level 1

                                          " It's hard to write the Application subclass itself in ActionScript, because of certain compiler magic"

                                           

                                          I'd like to understand what has to be done in ActionScript to replace the mxml Application file.  Do you have a pointer to docs for that?

                                           

                                           

                                          "Your initial confusion was over the difference between a "property" and a "style". MXML makes them look the same, but they are very different in ActionScript, and it isn't the purpose of the ASDoc reference to explain the difference; that's covered elsewhere."

                                           

                                          I'd appreciate a pointer to the "elsewhere".

                                           

                                          Thanks.

                                          • 19. Re: Is there an ActionScript reference for Flex?
                                            GordonSmith Level 4

                                            > I'd like to understand what has to be done in ActionScript to replace the mxml Application file.Do you have a pointer to docs for that?

                                             

                                            I don't think this is documented, because it isn't a practice that we've recommended. But I'm pretty sure that developers have used the -keep compiler option to look at the ActionScript generated for a simple "Hello World" MXML app and then copied it or written equivalent setup code.

                                             

                                            The main thing I'm aware of that the framework requires, but which you don't get with extra work in a pure-ActionScript Application, is default values for CSS styles, as specified in the frameworks/projects/framework/defaults.css file. The MXML compiler autogenerates ActionScript to create CSSStyleDeclarations instances representing each CSS selector, and installs them into the StyleManager. Without this, when the component call getStyle("foo") they get undefined and some of them subsequently throw RTEs as a result.

                                             

                                            But it almost certainly is easier to write your application as

                                             

                                            <Application/>

                                             

                                            to let the MXML compiler do its thing, and then, if you insist, code everything else -- such as creating the children of the app and setting up event handlers -- in pure ActionScript.

                                             

                                            >>  "property" and "style".. it isn't the purpose of the ASDoc reference to explain the difference; that's covered elsewhere.

                                            > I'd appreciate a pointer to the "elsewhere".

                                             

                                            Hmm... I'm going to be of less help on that. I'm afraid that as a framework engineer I'm mainly familiar with the ASDoc reference, because we framework engineers write it. It actually gets generated from our comments in the source code for each property, method, event, etc. (and then polished by our doc team.) The rest of the Flex documentation set gets written by the separate doc team, and, although I've reviewed an occasional chapter, I've never familiarized myself with the complete set. Hopefully someone else can point out where basic framework concepts like styles vs. properties are discussed. It would be very embarrassing if our documentation never bothered to explain this!

                                             

                                            Gordon Smith

                                            Adobe Flex SDK Team