Navigace



Yet another first Apollo app - Lyric Finder

I was going through the blogs and found that I was pretty late in releasing my first Apollo app.

So I decided to play around with Apollo and build something. It's a Lyric Finder (I know... very stupid creative name). It uses lyricwiki as source and some regular expressions to interpret the results.

I know there should be an easier way to do that using some sexy webservices, but as I'm still learning the stuff....

And it also helped me to realize that I'm still pretty bad in AS3

The download link is on the bottom of this POST

<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   
   <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent;
    private function getResults(event:ResultEvent):void
    {
       var str:String = event.result.toString();
       var pattern:RegExp = /<div id="lyric">.*?<\/div>/
       var returnStr:String = pattern.exec(str)
       
       if(returnStr != null){
       requestResult.htmlText = pattern.exec(str);
    }
    else{
       requestResult.htmlText = "No Matches Found";
    }
    }
    private function doSearch():void
    {
       import mx.controls.Alert;
       var url:String = "http://lyricwiki.org/";
       var queryStrURL:String = prepareString(artistCriteria.text,songCriteria.text);
       var newURL:String = url + queryStrURL;
       
       trace(newURL);
       
       pageRequest.url=newURL;
       pageRequest.send()
       lbl_res.text="Results For:";
       lbl_details.text = capFirst(artistCriteria.text," ") + " - " + capFirst(songCriteria.text," ");
    }
   
    private function prepareString(artist:String,track:String):String
    {
       var newArtist:String = capFirst(artist,"_");
       var newTrack:String = capFirst(track,"_");
       
       return newArtist + ":" + newTrack;
    }
    private function capFirst(txt:String,delimiter:String):String{
      var str:String = txt;
      var aSTR:Array = str.split(" ");
      var i:int;
      var uString:String;
      var newStr:String = "";
      var strSpace:String = "";
      
      for (i = 0; i < aSTR.length; i++) {
       uString = aSTR[i].substr(0, 1).toUpperCase() + aSTR[i].substr(1);
       newStr = newStr + strSpace + uString
       strSpace = delimiter;
      }
      return newStr
    }
    ]]>
   </mx:Script>

   <mx:HTTPService url="http://www.placona.co.uk" id="pageRequest" method="GET" resultFormat="text" result="getResults(event)"/>
   
   <!-- The search Criteria here -->
   <mx:TextInput id="artistCriteria" width="127.5" text="Type the artist name" click="artistCriteria.text=''" bottom="10" right="272.5"/>
   <mx:TextInput id="songCriteria" width="135.5" text="Type the song name" click="songCriteria.text=''" bottom="10" right="83"/>
   
   <!-- My Labels -->
   <mx:Label text="Artist:" bottom="10" right="403"/>
   <mx:Label text="Song:" bottom="10" right="226.5"/>
   <mx:Label width="75" height="17" left="24" top="10" id="lbl_res" fontFamily="Verdana" fontWeight="bold" alpha="0.0"/>
   <mx:Label y="28" horizontalCenter="0" width="265" id="lbl_details" textAlign="center" fontWeight="bold" color="#ff0000" fontSize="12"/>
   
   <!-- Displaying it -->
   <mx:HTML width="445" id="requestResult" height="263" verticalCenter="2.5" horizontalCenter="0" fontFamily="Verdana" fontSize="10"/>
   
   <!-- the button -->
   <mx:Button label="Search" id="loadWeb" bottom="10" click="doSearch()" right="10"/>
   <mx:Text text="placona.co.uk" top="10" alpha="0.5" color="#400000" fontWeight="bold" id="placona" click="" right="8"/>
</mx:ApolloApplication>


AS3 my own implementation of capFirst()

I'm just studying a little bit of Flex and Action Script 3. Basically to be able to build some tiny gadgets using Apollo.

While building one of them, I came up with the following function:

private function capFirst(txt:String):String{
            var str:String = txt;
            var aSTR:Array = str.split(" ");
            var i:int;
            var uString:String;
            var newStr:String = "";
            var strSpace:String = "";
            
            for (i = 0; i < aSTR.length; i++) {
             uString = aSTR[i].substr(0, 1).toUpperCase() + aSTR[i].substr(1);
             newStr = newStr + strSpace + uString
             strSpace = " ";
            }
            return newStr
         }

Basically what it does is take all the first letters of each word of the string given and return them in upper case.

I think I've seen this before somewhere ;-).

Not sure if there's any easier way of doing that, but for my first steps it's just fine.


Search


Calendar

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Subscribe

Enter your email address to subscribe to this blog.


Archives By Subject

Adobe (14) [RSS]
Adobe Max 2007 (1) [RSS]
Apollo (2) [RSS]
CFDevcon06 (2) [RSS]
CFDevcon08 (1) [RSS]
CFUNITED 2008 (2) [RSS]
CFUNITED2007 (1) [RSS]
ColdFusion (31) [RSS]
Flex (3) [RSS]
General Techie Stuff (6) [RSS]
Javascript (1) [RSS]
Linux (5) [RSS]
Misc (24) [RSS]
Scotch on th Rocks2007 (1) [RSS]
Tag of the day (2) [RSS]
UKCFUG (1) [RSS]

Tags

adobe coldfusion misc

Recent Entries

No recent entries.

Adds


RSS


Add to Technorati Favorites


SpamStop

This blog is protected by the SpamStop plugin and Project Honeypot.
Handled in almost 2 month:
  • Total suspicious visitors: 50
  • Spammers: 16
  • and 34 where marked as suspicious.
The last shady visitor was here on August 22, 2008

In almost 2 month this blog was visited 42 times by search engines and other harmless crawlers and aggregators.

More info:
SpamStop plugin
Project Honeypot