admin on November 28th, 2008

Whilst working on an update to snippet manager, I was looking for the easiest way to introduce syntax highlighting and came up with one solution. I did not want to write syntax colouring procedures entirely in ActionScript, this seems like a bad idea to me as there are existing highlighting libraries available in JavaScript. So, I decided to try to encorporate an existing JavaScript library into a Flex application for AIR.

 

In this tutorial, I will show you a basic example of how to use the SHJS (Syntax Highlighting in JavaScript) library inside a Flex/AIR application.

For simplicity, In this example will use only the PHP Syntax Highlighting filter, but SHJS supports many more (Bison, C/C++, C#, ChangeLog, CSS, Diff, Flex, HTML, Java, JavaScript, LaTeX, Log files, M4, Makefile, Oracle SQL, Pascal, Perl, PHP, Prolog, Python, Ruby, Shell, SQL, Tcl, XML)

In order to run this example, there are some files from the SHJS library required, these are:

  • sh_style.min.css
  • sh_main.min.js
  • sh_php.min.js

(You can grab these files from the SHJS sourceforge website – or download them in the example zip file below)

1. Create the AIR application file. highlight-app.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.0">
<id>highlight.syntax</id>
<version>1.0</version>
<filename>highlight</filename>
<initialWindow>
<content>highlight.swf</content>
<visible>true</visible>
<width>650</width>
<height>350</height>
</initialWindow>
</application>

2. Create the Flex application file. highlight.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:highlight="*"
showFlexChrome="true"
pageTitle="Syntax Highlight"
layout="absolute" title="Syntax Highlight"
initialize="init();">

<mx:Script>
<![CDATA[
private function init():void {
textZ.text = "<?php\n for($i=0;$i<100;$i++){\n  echo 'line '+$i+'<br />';\n }\n?>";
}
private function syntaxColoring():void {
htmlZ.htmlLoader.window.highlightString(textZ.text,'php');
htmlZ.htmlLoader.window.sh_highlightDocument();
}
]]>
</mx:Script>

<mx:Panel x="10" y="10" width="252" height="100%"
layout="absolute" title="Enter Code Below">
<mx:TextArea id="textZ" color="#000000"
fontSize="11" fontFamily="Courier New"
editable="true" wordWrap="true"
width="100%" height="100%"/>
</mx:Panel>
<mx:Panel x="375" y="10" width="252" height="100%"
layout="absolute" title="Highlighted Code">
<mx:HTML
id="htmlZ"
location="syntax.htm"
enabled="true"
paddingLeft="4"
paddingRight="4"
width="100%" height="100%"/>
</mx:Panel>
<mx:Button x="270" y="65" label="Highlight &gt;&gt;"
click="syntaxColoring()"/>

</mx:WindowedApplication>

3. Create the syntax highlighting html file. syntax.htm

<link rel="stylesheet" href="sh/sh_style.min.css">
<script src="sh/sh_main.min.js"></script>
<script src="sh/sh_php.min.js"></script>

<script>
function highlightString(st,lang) {
document.getElementById('sourcecode').className = 'sh_'+lang;
document.getElementById('sourcecode').innerText = st;
}
</script>
<pre id="sourcecode"></pre>

 

Syntax Highlighting Example Flex / AIR

Syntax Highlighting Example Flex / AIR

Download all required files in this example: flex_syntax_highlight_example.zip

Tags: , , ,

admin on November 27th, 2008

I recently released an AIR application called ‘Snippet Manager‘ which was build using Flex (in a basic text editor, not Flex Builder). Today I decided to see if it would work on Linux. I’m happy to report snippet manager works just as well as it does in Windows.

Here are the steps I used to install Adobe AIR on Linux (Ubuntu).

Note: On my system, I used VM Player (the Free Virtual Machine Player) inside Windows XP. I then downloaded a Linux Ubuntu 8.10 image (I got mine from vmplanet.net).

Step 1
Download the latest Adobe AIR Installer for Linux. At the time of writing, the Adobe AIR for Linux is in Beta.

Download Adobe AIR Linux Installer

Download Adobe AIR Linux Installer

Download the Linux install file from: http://labs.adobe.com/downloads/air_linux.html

If your browser is set to download files to your desktop (FireFox default on Ubuntu), you should see something like this:

Air Installer file on Linux Desktop

Air Installer file on Linux Desktop

 

Step 2
The next thing to do is find out your installer files location path. You can do this by right clicking on the file and selecting ‘Properties’. You should see something like this:

AIR Installation File Location

AIR Installation File Location

On my system, the file location is /home/vmplanet/Desktop/adobeair_linux_b1_091508.bin – the chances are the ‘vmplanet’ part of the path will be your own username.

Step 3 and 4
Now we need to change the file permissions (this could probably be done in the properties window, but we will do it in a terminal just to be sure!)

Open a terminal window (select terminal from the applications list). Type in the following command to change to the same directory as the installation file:

cd /home/vmplanet/Desktop

(you will probably need to change the path a little to match your own)

Now to change the file permissions, type:

chmod 777 adobeair_linux_b1_091508.bin

The final step will execute the installer file (installs Adovbe AIR). In your terminal window, type:

./adobeair_linux_b1_091508.bin

then press enter. The . (dot) at the front of your path is required!

 

Installing AIR on Linux Command Window

Installing AIR on Linux Command Window

You should now have Adobe AIR installed and ready on your Linux box.

To test it out, try installing our Snippet Manager application

Tags: , , ,

admin on November 25th, 2008

Today Ext LLC, the authors of the popular ExtJS JavaScript Library, released an updated version of Ext.AIR. The update includes many enhancements to sound support, windowing and database. They also include some new features for Ext AIR dealing with notifications, clipboard usage and the file system interactions. Here is a brief introduction to some of the notible features.

Ext.air.MusicPlayer

…supports all of the basic operations, stop, pause, play and skipTo along with supporting events. The MusicPlayer enables the developer to add music and podcasts to their AIR-enabled Ext application very quickly.

Ext.air.Notify

…allows you to notify users that something important has occurred even when your application may not be visible. By displaying these notifications at the operating system level it is sure to get the users attention without being lost within a browser tab.

Window and App API’s

Ext.air.NativeWindow now exposes methods to re-order windows, set a window as always on top, and enable full-screen mode. A new singleton, Ext.air.App will allow you to set your application to start on login and get the currently active window.

Ext.air.Clipboard

…allows you to interact with the system’s clipboard. Developers can determine if a particular format has data, set the data and get the data.

Ext.air.VideoPanel

…enables you to embed flash based video while maintaining the same functionality as an Ext.Panel…You can even watch the video fullscreen in high definition.

It’s still early days for Ext and AIR, but this is a great step to enabling developers to see the full potential of Adobe AIR and JavaScript.

With the above release, ExtJS have bundled in a sample application which uses the new Sound features (mainly). They are calling it ExtPlayer. It runs surprisingly well for a first example, however I could not get the timeline drag to move without the whole player moving too… but it is a great concept player.

ExtPlayer in action.

ExtPlayer in action.

You can find out more about Ext.Air here

Tags: ,

admin on November 24th, 2008

Sitepen, the authors of the popular open source javascript library Dojo, have released a new set of extentions specifically designed for Adobe AIR.

Dojo Extensions for Adobe AIR is available right now.

Sample Application:

“Created by SitePen and co-sponsored by Adobe®, the Dojo Toolbox was developed using the Dojo Toolkit and Adobe® AIR™. The Dojo Toolbox offers a great user experience and simplifies your creation of amazing web applications.”

They have created the entire API using the namepace of ‘dair’ (I image that is: Dojo Adobe Integrated Runtime, but don’t quote me on that!), you can use:
dair.AIR, dair.Console, dair.Window, dair.Application, dair.fx, dair.Sound, dair.Video, dair.Icon and dair.File. They will be releasing dair.Chrome pretty soon too.

Dojo is release under the Open Source BSD-license…. Nice!

Tags: , , ,