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 view the cloud not as a specific technology but as a way of doing business and that way of doing business is transforming the way software, infrastructure and services are being delivered to business," explained Matthew Rosen, CEO and Director at Fusion, in this SYS-CON.tv interview at 18th Cloud Expo (http://www.CloudComputingExpo.com), held June 7-9 at the Javits Center in New York City, NY.
The Founder of NostaLab and a member of the Google Health Advisory Board, John is a unique combination of strategic thinker, marketer and entrepreneur. His career was built on the "science of advertising" combining strategy, creativity and marketing for industry-leading results. Combined with his ability to communicate complicated scientific concepts in a way that consumers and scientists alike can appreciate, John is a sought-after speaker for conferences on the forefront of healthcare science,...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
In his session at Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to maximize project result...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at @ThingsExpo, James Kirkland, Red Hat's Chief Archi...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...