Indic Transliterator in Flex… powered by Google Labs

September 4, 2007

I saw this post on Abdul’s blog today. Google Indic Transliterator is cool. I played around with it a bit and then it stemmed a desire to do something similar in Flex. Thanks to the pointer by Abdul, I was able to achieve this.

Abdul, in his post talks of an URL (click on the link to see an example of what I’m talking about) which you can hit with your text through GET parameters and get it transliterated. The result, if tweaked a bit (i.e. removing unwanted characters including some escape characters) would yield a JSON.

Then I used the as3corelib to convert the JSON to an AS Object. I then embedded an Indic Font into my App and used it to render the text. The result is what you see below.

I’m not posting the code as of now because its still a very dirty 🙂 And also, the API is undocumented and may break soon. But I guess this should be pretty straight forward for anyone who wants to try this out…

Advertisements

Flex In India – Updates

August 6, 2007

Web2.0 is spreading in India and so is Flex with it 🙂

After a succesful semester of “Web2.0 & RIA (Rich Internet Applications)” elective at IITB, Bangalore (for which, I’m proud to be a part of the visiting industry faculty), the much desired course has now made it into the curriculum of the Visvesvaraya Technological University (VTU).

VTU is a university that has 111 affiliated colleges in the state of Karnataka, in India (kind of apt, as Bangalore, hailed as the Silicon Valley of the East is the capital of this state). The university provides heavily for the demand for IT & Computer engineers for the booming IT & IT Enabled Services industry in the country.

The course ware consists of the following parts…

  • Overview of We2.0 and its perceptions
  • Key concepts in Web2.0
  • Overview of Data Handling in RIAs -This includes technologies like WebServices, E4X, XML
  • Introduction to Open Source Flex2.0
  • Introduction to AJAX
  • … some more

I’m mighty interested and excited about this. Hope I’ll get to be a part of this, just like the IITB venture.

Please, everyone spread the news and ask the students you know to request and signup for this elective in their respective colleges. Lets make this a grand success and a precursor of more to come… Go RIA… Go Flex 🙂


JSON to ASON

June 2, 2007

I have blogged about JSON before but forgot to provide an example for getting JSON into AS. I saw a query on FlexIndia on JSON, so I thought I’ll post it now. The problem is to convert JSON to ActionScript Objects (or ASON). You can first try the demo application to see if this is what you are looking for…

In the app, you can either paste a URL (provided you have the security permissions) of a JSON to convert or paste your own JSON into the textarea and convert it.

This is what you need to do to get this working…

  1. Go to AS3CoreLib on Google Code and download the corelib-.90.zip file and extract it
  2. Get the corelib.swc from the /bin directory
  3. Download the app source or write your own code 🙂
  4. Do one of the following:
    If you are using FlexBuilder:

    1. Right click on your project go to Properties
    2. Navigate to Flex Build Path -> Libraries Tab -> Add SWC
    3. Now add the corelib.swc to your project
    4. Confirm that you have the line “import com.adobe.serialization.json.JSON;” in the code
    5. Run and Have Fun 🙂

    If you are using the command-line compiler:

    1. Place the swc in the directory of your mxml code
    2. Confirm that you have the line “import com.adobe.serialization.json.JSON;” in the code
    3. Type the following on the command line
    4. mxmlc -include-libraries=corelib.swc JSONTest.mxml
    5. Run and Have Fun 🙂

What’s the Big Deal with E4X support in AS3

April 5, 2007

I couldn’t place the excitement in the team last year when we announced support for E4X in AS3. As a newbie in the XML arena, ignorant of the XML parsing woes in Flash & of terms like XPath, i really didn’t think its a big deal. My views have changed… a lot.

The traditional way of dealing with XML in Flash is using the The XMLDocument, XMLNode and XMLNodeType Classes (checkout the flash.xml package in the live docs). Say you have an XML as follows as myXML (in an XMLDocument Object)

<employeeList>
<employee id=”475″>
<lastName>Zmed</lastName>
<firstName>Sue</firstName>
<position>Data analyst</position>
</employee>
<employee id=”348″>
<lastName>McGee</lastName>
<firstName>Chuck</firstName>
<position>Jr. data analyst</position>
</employee>
</employeeList>

In legacy AS2, if you want to access the employee id of McGee i.e. 348, you need to access as :

myXML.firstChild.childNodes[1].attributes.id

If you want the firstname of McGee i.e. Chuck, you need to access as:

myXML.firstChild.childNodes[1].childNodes[1].firstChild.nodeName

Come AS3 & E4X and life becomes a walk in the park. Declare the myXML as an XML Object (native e4X xml type in As3)

You want McGee’s id ??? here it is

(myXML..employee)[1].@id

myXML..employee generates an XMLList (another E4X compatible class) by parsing the XML to generate only XML nodes with employee as the node (with its children). So myXML..employee generates

<employee id=”475″>
<lastName>Zmed</lastName>
<firstName>Sue</firstName>
<position>Data analyst</position>
</employee>
<employee id=”348″>
<lastName>McGee</lastName>
<firstName>Chuck</firstName>
<position>Jr. data analyst</position>
</employee>

To get McGee’s FirstName…

(myXML..employee)[1].firstName
OR (myXML..firstName)[1]

Also, you can run XPath2.0 queries on the resultant XML.For e.g., consider the following statement…

(myXML..employee.(@id>400)

It returns all employee nodes in the xml that has an employee id>400, which in this case is “Sue Zemed”. Cool ! E4X Rocks…

Check out the XML & XMLList classes in the livedocs. If you need more info on E4X, refer the following links


JSON – A lightweight way of passing Data

March 10, 2007

I was at the Web2.0 Conference held by the Computer Society of India Bangalore Chapter (CSIBC) at Royal Orchid in Bangalore. There was Philip from Yahoo Bangalore talking on JSON.

JSON
(JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. The advantage of JSON is that its very light-weight and has none of the markup problems associated with the XML Interchange. Its fast evolving as a preferred data-interchange format, majorly being pushed by Yahoo. Its really worth taking a look at. Yahoo is giving a lot of its Services which were traditionally XML based now in JSON & serialized PHP as well. Here are some links that will let you deep-dive in JSON.

I was really excited with JSON and started some primary explorations with it. It turned up an AS3 Core Lib, which includes a JSON parser for AS3 (i.e FLEX). I will put up a Yahoo Photo Search soon with JSON and using the AS3-JSON Parser