Welcome!

Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex

Adobe Flex: Article

Do You Speak Web?

A look at a young, new programming language - haXe

The recent years of Web development have been marked by several important events. In the Flash world, we have seen a constant evolution of the technology. From a developer's point of view, Flash started to be really usable with the introduction of ActionScript 1.0 in Flash 5 and the improvements made in Flash 6. It turned out that Flash was no longer only an animation tool for designers but also a framework for developers. This led to many Flash projects that would not have been possible before, ranging from Web games to Rich Internet Applications.

Flash
The usage of Flash by developers has been greatly increased over the years. With the introduction of ActionScript 2, people familiar with existing object-oriented language such as Java could start developing Flash content more easily. With the new graphical effects of Flash 8, game visuals could be greatly improved. And even more recently with Flex2 components, one can now develop a working RIA in a matter of hours.

However, with all these additions, a lot of early Flash adopters might have been left behind, lacking time to learn all these new technologies and at the same time, feeling pressured by all the new exciting things that were becoming possible. This development will be ongoing, and actually, for someone who wants to develop a modern Web site, there is even more to learn.

The second major change was the progressive replacement of Internet Explorer 5-generation by IE6, which integrated better JavaScript and CSS support. Together with the emergence of standard-compliant browsers such as Firefox, Safari and Opera, this led to the next hot thing - AJAX.

In the Web world, where not everybody needs the very complex interactions that Flash can provide, AJAX works well with Flash to provide an enhanced user experience. For the Flash developer who wants to use some AJAX features in his existing Web site, the technologies are complementary.

The Server-Side of Things
In order to develop a Web site, you also need to know some server-side technology. Since the unique Perl CGI choice from a few years ago, a lot of server-side languages are now available, including Java, PHP, ASP, Python, and more recently, Ruby-on-Rails. All these languages are clearing the gap by providing indirect and filtered access to the server filesystem and database.

To master server-side technologies, you need to learn a good number of frameworks, sometimes concurrent, rarely standardized. You need also to understand how to communicate efficiently with the client-side, either with Flash (by using Remoting) or JavaScript (using XML or JSON).

Issues
Whether for the single developer or the team that has mastered all these different technologies, a set of new problems arises from using them all together in one Web site. Communications between the different developers of a team are not always easy since they use different technologies. Sending messages between the different languages is not always transparent, due to their technical differences, so an XML intermediate representation is often needed, which adds duplicate work for both client and server. And since different languages are preventing code reusability, developers need to write the same code twice, and keep everything synchronized. A typical example is a complex form validation that needs to be performed on both server- and client-side. That's where haXe comes in.

What Is haXe?
haXe is a new technology that simplifies Web development by providing a common foundation programming language for both client- and server-side technologies. You can use haXe to program Flash, JavaScript/AJAX, and the server-side of your Web site. You can even use haXe to develop desktop applications.

By reducing the number of pieces in the Web puzzle, haXe simplifies the overall Web site development process. Because the developers in a team are all using the same technology, they can understand each other and share ideas more efficiently. Since this is the same language everywhere, messages can be sent transparently between the different layers of the Web site, enabling full Flash/JS/Server automated communications. And with the same syntax for all platforms, some code can be reused on both the server- and client-side, without having to rewrite it or keep everything synchronized.

For the Flash developer, haXe is a command-line compiler that can be used to compile a set of haXe classes into a SWF file. Flash Players from 6 to 9 are supported, giving the haXe developer a lot of freedom of choice (ActionScript3, by comparison, only supports Flash Player 9). For people already familiar with the MTASC ActionScript2 compiler, haXe is its successor.

To develop JavaScript/AJAX code, the haXe compiler will output a single .js file, including all the compiled classes. Programming haXe instead of JavaScript is increasing productivity: haXe is strongly typed so most errors are caught early in the compilation phase. haXe is class-based so the JS developer can abstract some visual components into classes and reuse them later in several projects. Since only needed classes are compiled to the .js file, it's easier to manage than a lot of small .js includes. More importantly, haXe-generated JavaScript code is cross-browser, and haXe includes some standard libraries - such as XML manipulation and XmlHttpRequest - needed to write cross-browser AJAX code.

Finally, haXe classes can be compiled to run on the Neko Virtual Machine - a small embeddable VM with a low footprint and very good performance. There is a mod_neko for the Apache Web Server (similar to mod_perl or mod_php), so you can use haXe to connect to a database and generate dynamic Web pages. Standardized API are available to wrap database tables using classes (SPOD), generating HTML from a Template system, or simply accessing the local filesystem and network.

This article will focus its examples on both JavaScript and Flash technologies, which might be more familiar to the reader.

haXe API
haXe is sometimes wrongly accused of trying to do too many things at one time, with the belief that it will somehow be the less common denominator between all these platforms. But that's not how haXe works.

haXe is a programming language with which you can define classes and write code. It has a standard library that has been unit-tested to work the same on all platforms. This standard library includes API such as XML, String, Date, Array, and Reflection.

Each platform has its own specific API, such as Browser DOM for JS, MovieClip and Sound for Flash, database and filesystem for Neko. These APIs are the same ones you would usually use in ActionScript or JavaScript. This makes haXe very easy to learn; all you need to do is to adapt to the small differences in haXe syntax.

Hello haXe!
Everything I've said until now might sound like nothing more than a nice theory, so let's dive into practical programming to see how things are working in the real world.

class Hello {
    static function main() {
       trace("Hello haXe !");
    }
}

This class is the most simple haXe example. Let's try to compile and run it on the three supported platforms. For that, we need to write an .hxml file that will list compiler parameters:

-main Hello
-swf hello.swf

If haXe is installed, you should be able to run the HXML file by double-clicking on it, and running it from the command line by using "haxe file.hxml". This will produce a hello.swf file that, when opened, will display the text directly on the screen. Now, let's change the HXML file to compile for JavaScript instead of Flash:

-main Hello
-js hello.js

Again, this will produce a hello.js file. Let's include the JS in the following HTML page and open it:

<html>
    <body>
      <div id="haxe:trace"></div>
      <script type="text/JavaScript" src="hello.js"></script>
    </body>
</html>

That will display the text at the position of the div. As you will have noticed, this is not terribly different from what one would write in Java or ActionScript. haXe syntax is very user-friendly and 90% compatible with most popular programming languages. Therefore, it's easy for any programmer familiar with one of these languages to write haXe code.

Multiplatform haXe Code
So how is the trace function - which has different behavior depending on the platform - implemented? Is it some kind of haXe black magic? Not exactly. While platform-specific code can't be compiled for other platforms, haXe accepts conditional compilation statements that enable a different implementation depending on the platform. For example, let's look at the following method:

function displayError( msg : String ) {
    #if flash
      // flash-specific code
      var mc = flash.Lib._root;
      mc.createTextField("tf",mc.getNextHighestDepth(),0,0,100,30);
      mc.tf.text = msg;
      mc.tf.textColor = 0xFF0000;
    #else js
      // JavaScript-specific code
      js.Lib.alert(msg);
    #end
}

When the displayError function is compiled for Flash, it will use the Flash code, and when it's compiled for JavaScript, it will use the JavaScript code. This enables developers to have some code that - while using platform-specific code - can be compiled and run on the different platforms. This is actually the way some of the haXe standard libraries are implemented.


Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Mobile device usage has increased exponentially during the past several years, as consumers rely on handhelds for everything from news and weather to banking and purchases. What can we expect in the next few years? The way in which we interact with our devices will fundamentally change, as businesses leverage Artificial Intelligence. We already see this taking shape as businesses leverage AI for cost savings and customer responsiveness. This trend will continue, as AI is used for more sophistica...
SYS-CON Events announced today that SourceForge has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. SourceForge is the largest, most trusted destination for Open Source Software development, collaboration, discovery and download on the web serving over 32 million viewers, 150 million downloads and over 460,000 active development projects each and every month.
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
While some developers care passionately about how data centers and clouds are architected, for most, it is only the end result that matters. To the majority of companies, technology exists to solve a business problem, and only delivers value when it is solving that problem. 2017 brings the mainstream adoption of containers for production workloads. In his session at 21st Cloud Expo, Ben McCormack, VP of Operations at Evernote, will discuss how data centers of the future will be managed, how th...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...