7 Replies Latest reply on Jun 24, 2007 8:12 PM by Newsgroup_User

    Using Ruby in place of Actionscript

    ryanmohr
      I love flash (design tools, stage / layout concepts, etc.), but I hate actionscript. I've been a programmer for about 10 years now, programming in everything from C to C#, java, php, perl, ruby, and actionscript. Actionscript is by far my least favorite of the group. It is a clumsy language (just have a look at the way actionscript 2 handled method closures on callbacks) and I'd prefer to use another scripting language in place of it for my flash development. Ruby would be an excellent replacement, offering everything actionscript has to offer (object oriented, event handling, etc.) with a number of additional features that come through ruby core and the ruby gems (excellent date and time libraries, database libraries, file handling libraries, etc.).

      Does anyone with an in-depth knowledge of actionscript and flash know what it would take to achieve some sort of common language API that would allow such a substitution? If the ruby on rails guys came across a solution allowing them to leverage the benefits of ruby (superior language to actionscript) with the benefits of the flash platform (superior visual control to html/ajax), flash would be unstoppable.
        • 1. Re: Using Ruby in place of Actionscript
          Level 7
          ryanmohr,

          > I love flash (design tools, stage / layout concepts, etc.), but
          > I hate actionscript. I've been a programmer for about 10
          > years now, programming in everything from C to C#, java,
          > php, perl, ruby, and actionscript. Actionscript is by far my
          > least favorite of the group.

          Heh, not Perl? Come one! ;)

          > It is a clumsy language (just have a look at the way actionscript
          > 2 handled method closures on callbacks) and I'd prefer to use
          > another scripting language in place of it for my flash development.

          Have you taken a look at ActionScript 3.0 yet? Exactly what you've
          mentioned (and tons more) has been address, neatned, improved, and otherwise
          made cool. Native support for regex, runtime strongly typed variables,
          runtime exceptions, sealed classes....

          The Flex compiler (not the IDE, but the compiler itself) is even free.

          http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Using Ruby in place of Actionscript
            ryanmohr Level 1
            I have tried out AS3 and am not happy with it. I was really excited about trying it out (just to never have to deal with the quirks of AS2 ever again) but I've run into a number of nuisances, most of them largely centered around the recent strictness built into the language (sure it's more like java, but who wants another java?). The runtime exceptions don't even provide line numbers in the output window.

            It's not that actionscript is a bad language, it's just that ruby is that much better and that much less awkward to write code in. How's the new flash.display.Loader class, where you can no longer just say load("myurl") but now have to say load(URLRequest("myurl")) and also have to import URLRequest because of the new syntax. Don't even get me started on the new event handling process with the IEventDispatcher (take a look at the configureListeners method in this example if you don't know what I'm talking about: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html#includ eExamplesSummary

            It's the little things that bother me with actionscript. setInterval being deprecated for a much wordier Timer approach, the package syntax (have to wrap your whole class in brackets, why not just go with a 'package my.package;' style), the cryptic compile errors (came across one where I said "why don't you just tell me that I didn't explicitly declare my class as public? I thought I had a classpath problem".

            Basically a bunch of little things that all add up to a distaste for programming in actionscript. Ruby is an excellent language (both scripting and OO), capable of everything actionscript needs to be capable of and not far from what flash programmers are used to with actionscript 2. Why not just use ruby?
            • 3. Re: Using Ruby in place of Actionscript
              Level 7
              ryanmohr,

              > It's not that actionscript is a bad language, it's just that
              > ruby is that much better and that much less awkward
              > to write code in.
              > [numerous examples ... ]

              Fair enough. Different strokes for different folks. :)

              > Basically a bunch of little things that all add up to a
              > distaste for programming in actionscript. Ruby is an
              > excellent language (both scripting and OO), capable
              > of everything actionscript needs to be capable of and
              > not far from what flash programmers are used to with
              > actionscript 2.

              So it plays video, plays audio, produces cartoon content fit for
              television, produces online games, interactive art, etc.? I'm not asking to
              be snarky, I'm asking because I don't know ... I've only grazed the Ruby
              site. Does Ruby run on moble devices?

              > Why not just use ruby?

              I use Flash mainly because of its built-in support for multimedia
              audio-visual capabilities. That may not be your thing. There is a .NET API
              of some kind that outputs SWFs -- not that .NET sounds at all like your cup
              of tea -- but it has been done. So maybe it's not out of the realm of
              possibility for Ruby. I would see that as cool, personally (not just for
              Ruby, but any language) ... yet at the same time, I'd probably be forever
              worried about the decisions the API was making on my behalf. Even Flex uses
              MXML to eventually "write" AS3 code ... it's a layer of abstraction that I
              (so far) haven't been especially interested in.


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: Using Ruby in place of Actionscript
                ryanmohr Level 1
                Sorry, my original post was unclear. I wasn't arguing for ruby over flash/javascript, I was arguing for a combination of flash with ruby. Such that you would do your scripting in ruby rather than in actionscript (in the most basic terms, you'd have a collection of .rb files rather than .as files linked to your movieclips). All the media playback and interactive components would still be the same. Something similar to the .net approach with the CLR and the common language runtime components, where you use the .net language that suits the problem the best (and to your taste), and it all compiles into the same thing anyway.

                Yes flex compiles mxml into actionscript, but you are still using actionscript in those files. I'd like to use erb (embedded ruby) within the mxml files instead. Ruby is a much more powerful and elegant language than actionscript, allowing you to do something like this to read the contents of a file:

                * Ruby explantions
                -- puts is the equivalent to trace in actionscript
                -- comments start with # rather than //

                File.open("/tmp/myfile").each { |line|
                puts line # prints out the line
                }

                or something like this for grabbing data from a database:

                res = db.query("SELECT name FROM users")
                while row = res.fetch_row do
                puts row['name']
                end

                Imagine harnessing that power with the graphical abilities of flash. I'd be sold.
                • 5. Re: Using Ruby in place of Actionscript
                  Level 7
                  ryanmohr,

                  > Yes flex compiles mxml into actionscript, but you are
                  > still using actionscript in those files. I'd like to use erb
                  > (embedded ruby) within the mxml files instead.

                  I hear what you're saying. I think the closest possible scenario --
                  that I've seen, at any rate -- is the .NET thing I mentioned earlier (really
                  wish I could remember the name of it). Of course, even so, as with the MXML
                  conversion, you still end up with ActionScript, and it sounds like you don't
                  want that.

                  The thing is, ultimately, even ActionScript is further converted. Flash
                  Player plays bytecode that the Flash/Flex compiler produces from
                  ActionScript. Perhaps there's some app out there that can convert Ruby (or
                  any other language) to that bytecode, but, well ... the bytecode is what it
                  is. It requires Flash Player to run it. On its own, Flash Player does not
                  have access to the file system. That would take something like Apollo. So
                  no matter what -- even if someone produced a new compiler that compiled Ruby
                  to true Flash Platform bytecode ... you'd only be able to do, at best (at
                  the time of this writing) what Flash Player 9 is capable of doing.

                  > Imagine harnessing that power [Ruby example] with the
                  > graphical abilities of flash. I'd be sold.

                  There's no arguing taste, of course. ;) I look at Ruby, personally,
                  and it doesn't float my boat. I certainly wish you the best ... I wish you
                  could enjoy Flash as much as I do -- because I love it! Here's hoping
                  someone else will jump in on the thread with some open source project that
                  gives you what you're after. :)


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Using Ruby in place of Actionscript
                    ryanmohr Level 1
                    David,

                    You appear to be very knowledgeable both on actionscript and the inner-working of flash itself. I've been programming a lot in AS3 the past few days, and I've repeatedly found myself saying "why the hell don't they just offer __ as a convenience?". I've probably had half a dozen of these, but the few that stand out are:

                    * Utility methods for modifying child depth (such as moveUp, moveDown, bringToFront, sendToBack)
                    * Utility methods for modifying strings (there's no method in the core string class that will allow you to replace all occurrences of a pattern with another. sure you can use a global regex replace, or replace them one by one and loop until they are all gone, but why not just offer it built in with an easy to use syntax? String.replaceAll() perhaps? It would take what, a full five minutes for them to write? Other functions like startsWith, endsWith, trim, etc. should all be in there too as they are common string operations.

                    The actionscript developers seem to enjoy leaving the core libs unfinished so others can produce utility classes to finish the job they should have done on their own.

                    You are correct that there is no arguing taste, but if you took the time to learn ruby well you would come back to actionscript very disappointed. Instead of having to import extra utility classes and use static methods like StringUtils.startsWith("my string", "my") I'd much rather be able to just say "my string".startsWith("my"), even if I had to write that extension. In ruby you can do so with mixins, which allow you to extend the core functionality of any class you'd like and use those additional methods as though they were built into the native classes. You can even extend primitives such that you can write expressions like 7.days_ago == 1.week_ago .

                    The more I get to know actionscript 3 in detail the more I'm convinced those that adamantly support it just don't know any better. I used to love C++ and thought it was the best language ever. Of course, that was back when C++ was the only language I knew...
                    • 7. Re: Using Ruby in place of Actionscript
                      Level 7
                      ryanmohr,

                      > The actionscript developers seem to enjoy leaving the
                      > core libs unfinished so others can produce utility classes
                      > to finish the job they should have done on their own.

                      Again, fair enough. :) On the other hand, regarding the missing String
                      manipulation utilities ...

                      > but why not just offer it built in? It would take what, a
                      > full five minutes for them to write?

                      ... hey, if all it takes is five minutes of someone's time, why not craft
                      together a utils library and share it? You could make a positive
                      difference. :) In that line of thinking, it's not even the size that
                      matters. Moses Gunesh, for example, put together an elaborate and popular
                      tweening engine, Fuse ( http://www.mosessupposes.com/Fuse/), and shared the
                      wealth. Note: by proximity to a casual statement on a String utils class,
                      I risk implying that Fuse is just a five-minute exercise in simplicity,
                      which is not *at all* the case. I'm only pointing out that good libraries
                      can make a helpful difference in people's workaday lives. If the
                      functionality you want isn't available, roll your own! :)

                      > You are correct that there is no arguing taste, but if you
                      > took the time to learn ruby well you would come back
                      > to actionscript very disappointed.

                      Even if I do "appear to be very knowledgable ... [on] the inner-working
                      of Flash itself," I don't claim to know much on the inner-working of Adobe.
                      I guess it depends on one's point of view -- and to my point of view,
                      ActionScript keeps getting better and better.

                      I think there's more than just taste to consider. For the type of
                      programming I like to do -- where the end result is (ideally, to me) making
                      cartoon characters move in response to user input, Ruby might leave me dry
                      (Flash is strongly suited to vector graphics, sound effects, video footage,
                      etc.). My multimedia career started with Macromedia Director, whose
                      programming language is Lingo, a very AppleScript-like language. My guess
                      is that you wouldn't much care for it at all. From there, I moved,
                      reluctantly at first, to Flash, where my programming skill grew in-step with
                      the increasing maturity of ActionScript. There was a time, essentially AS1,
                      when ActionScript was practically identical to JavaScript, and I enjoyed
                      getting to know both. JavaScript led me to regular expressions, which
                      fascinated me for fully two years before I got any good at it. I'm pleased
                      as punch that AS3 supports regex natively. AS2 brought the "class"
                      keyword -- and OOP in general -- to the forefront of my mind, which led to
                      brief excursions into Java and C#. I've played a bit with Python, PHP, and
                      a handful of other languages. To a certain extent, programming is
                      programming: it's the syntax that changes, not the challenge and fun of
                      problem solving within a given set of constraints (like the language
                      itself). In that regard, it doesn't really matter to me what language I'm
                      using, so much as a general answer to the question, "Does this platform
                      allow me -- encourage me -- to participate in the kinds of projects I like?"
                      Even if I found another language, such as Ruby, more convenient, it might
                      not facilitate the sorts of projects I enjoy. To go out on a limb and make
                      an extreme example, Ruby, for all its elegance, wouldn't help me if I had a
                      passion for programming LCD wristwatches. Because I "grew up" on
                      ActionScript, I also have something of a nostalgia for its particular
                      quirks. I personally happen to find ActionScript more palatable than
                      Lingo -- so I can see some of your points.

                      > The more I get to know actionscript 3 in detail the more
                      > I'm convinced those that adamantly support it just don't
                      > know any better.

                      I don't know if you consider me one of those who adamantly supports AS3
                      or not, and it doesn't really matter. You yourself said that ActionScript
                      isn't a bad language -- only that Ruby, in your estimation, is that much
                      better. Well, good! I'm glad you've found a language that pleases your
                      palate. :) If you were to change your mind and decide, after all, that
                      ActionScript actually is a "bad language," it wouldn't be any skin off my
                      nose. See, if I step away from ActionScript toward something else, it means
                      I'm stepping away from a platform that has continued to intrigue me for
                      eight years. If ActionScript were still where it was in the Flash 4 days,
                      I'd probably be whistling a different tune. ;)


                      David Stiller
                      Adobe Community Expert
                      Dev blog, http://www.quip.net/blog/
                      "Luck is the residue of good design."