Another quick Apollo App

This post is more than 2 years old.

I'm just loving Apollo. This morning I built a quick regex tester. It only does global style matches, but it is a good first draft. Download it by clicking the Download link below.

In the next version I'll switch to using highlight on the original text instead of a dump of matches. I'll also let you try out replacements as well.

Enjoy my lovely design skills. The code is below for those who are curious.

<?xml version="1.0" encoding="utf-8"?> <mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Regular Expression Tester">

<mx:Script> <![CDATA[ private function testRegex():void { var regexStr:String = regex.text; var bodyStr:String = body.text;

results.text = '';

if(regexStr == '' || bodyStr == '') {
	mx.controls.Alert.show("Please enter a regex and a body.");
	return;
}

var regexOb:RegExp = new RegExp(regexStr,"g");
var matches:Array = bodyStr.match(regexOb);

if(matches != null && matches.length &gt; 0) {
	for(var i=0; i &lt; matches.length; i++) {
		results.text += matches[i] + "\n";
	}
}

} ]]> </mx:Script>

<mx:VDividedBox width="100%" height="100%">

&lt;mx:Panel title="Regex" width="100%" height="70" &gt;

	&lt;mx:HBox width="100%" height="100%"&gt;
		
		&lt;mx:TextInput id="regex" width="100%" height="100%"/&gt; &lt;mx:Button id="tstButton" label="Test Regular Expression" click="testRegex()" height="100%" /&gt;
		
	&lt;/mx:HBox&gt;
	
&lt;/mx:Panel&gt;

&lt;mx:Panel title="Body" width="100%"&gt;
	
	&lt;mx:TextArea id="body" width="100%" height="100%" /&gt;

&lt;/mx:Panel&gt;

&lt;mx:Panel title="Matches" width="100%"&gt;
	
	&lt;mx:TextArea id="results" width="100%" height="100%" editable="false" /&gt;

&lt;/mx:Panel&gt;

</mx:VDividedBox>

</mx:ApolloApplication>

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by John Ramon posted on 3/21/2007 at 6:40 PM

Nice Ray that's 2 apps for you and .1 for me the only thing I have made with Apollo is a Hello World app. Nothing like you stuff but at least I'm on the band wagon from the begging this time. I'm on Chapter 5 of "Adobe Flex 2: Training from the Source" and just ordered the Action Script 3.0 Cookbook.

I'm glad your take the time to talk about Flex and Apollo, it's helping me.

Comment 2 by Chad posted on 3/21/2007 at 6:45 PM

Ray is that just straight up javascript in your <![CDATA[ tag? Never knew you could do that.

Flex builder is complaining that var i has no type declaraction, and when i run my app it locks up when i submit the following.

regex
[0-9]*

body
123

Comment 3 by Raymond Camden posted on 3/21/2007 at 6:48 PM

It's not JS, its ActionScript 3. Both are based on ECMAScript, which is why it is so easy to learn one after you know the other.

Locks up eh? I bet I screwed something up in my loop.

I'm rewriting it RIGHT now to not use a textarea. Instead, I'm going to apply style sheets to the text matches.

Comment 4 by Chad posted on 3/21/2007 at 6:56 PM

After i read the code closer i realized it was AS. Guess it helps to actually read it. :)

It does not lock up if i use super simple RE like.

regex
123

body
abc123

Cant wait to the the CSS stuff. I have not seen code examples of that.

Comment 5 by Ben Nadel posted on 3/21/2007 at 9:22 PM

All this Apollo talk lately has gotten me depressed :) I want to be on the band wagon too. That's a cool little app you made Ray. Makes me want to stop right now and got try this Apollo stuff.

Comment 6 by Joshua Curtiss posted on 3/21/2007 at 10:48 PM

<rant>
Ugh. I know AS is so much like JavaScript (and I love JavaScript), but I always thought I could avoid having to learn AS since I stayed away from Flash. Now with Flex and Apollo, it seems inevitable that ActionScript will become yet another language web developers in the Adobe/ColdFusion realm will have to pick up.

What happened to the good old days when an app was written in one language? :-D
</rant>