deepak verma

September 6, 2007

Flex 1.5 to Flex 2 actionscript converter

Filed under: Flex — deepuverma @ 6:22 pm

I had been asked by my manager on how much time will it take to convert the intranet Flex 1.5 application to Flex2. Instead of doing the basic stuff for converting the app manually, I thought of writing a utility of replacing code.

The utility takes care of the following

I . Finds and replace
1. application namespace
2. Void with void
3. newline with \n in .as file
4. _root with Application.application
5. Application.alert with mx.controls.Alert

II. package the class

Following are the regular expressions I have used to replace the content (not sure if this is the best way to do the task)

file_content = Regex.Replace(file_content, "xmlns:mx=\"http://www.macromedia.com/2003/mxml\"", "xmlns:mx=\"http://www.adobe.com/2006/mxml\"");
file_content = Regex.Replace(file_content, "\bvoid\b", "void",RegexOptions.IgnoreCase);
if (fi.Extension == ".as")
{
file_content = Regex.Replace(file_content, "\bnewline\b", "\"\n\"", RegexOptions.IgnoreCase);
}
else
{
file_content = Regex.Replace(file_content, "newline", "#&13;", RegexOptions.IgnoreCase);
}
file_content = Regex.Replace(file_content, "\b_root[.]\b", "Application.application.", RegexOptions.IgnoreCase);
file_content = Regex.Replace(file_content, "\bApplication.alert\(", "mx.controls.Alert.show(", RegexOptions.IgnoreCase);
String packagename;
if (fi.Extension == ".as")
{
Match m = Regex.Match(file_content, @"(?<class>class)(?<packages>.*[.])(?<classname>.*)");
file_content = Regex.Replace(file_content, @"(?<class>class)(?<packages>.*[.])(?<classname>.*)", "${class} ${classname}");
packagename = m.Groups["packages"].Value;
file_content = "package " + packagename.Substring(0, packagename.Length - 1) + "{n" + file_content;
file_content = file_content + "n}n";
}

1 Comment »

  1. I liked the new layout :)

    Comment by Debabrata Acharjee — September 24, 2007 @ 10:59 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.