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
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
The financial services market is one of the most data-driven industries in the world, yet it’s bogged down by legacy CPU technologies that simply can’t keep up with the task of querying and visualizing billions of records. In his session at 20th Cloud Expo, Karthik Lalithraj, a Principal Solutions Architect at Kinetica, discussed how the advent of advanced in-database analytics on the GPU makes it possible to run sophisticated data science workloads on the same database that is housing the rich...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, 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. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
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.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, 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. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
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.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that EnterpriseTech 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. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effic...
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 Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, 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. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and ...
SYS-CON Events announced today that CHEETAH Training & Innovation 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. CHEETAH Training & Innovation is a cloud consulting and IT training firm specializing in improving clients cloud strategies and infrastructures for medium to large companies.
SYS-CON Events announced today that Datanami 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. Datanami is a communication channel dedicated to providing insight, analysis and up-to-the-minute information about emerging trends and solutions in Big Data. The publication sheds light on all cutting-edge technologies including networking, storage and applications, and thei...