25
Apr

Left trim and right trim actionScript functions

Posted By wassim in Flash, Flash Tutorials

Left trim and right trim actionScript functions
These useful functions (lTrim and rTrim) are available in almost all programming languages yet not in actionScript, so here’s how to write ones yourself:
lTrim is easier, so we’ll start with that:

Actionscript:
  1. function lTrim(txt:String):String {
  2.     while
  3.             (txt.charAt(0)==" "
  4.             ||txt.charAt(0)=="\t"
  5.             || txt.charAt(0)=="\n"
  6.             || txt.charAt(0)=="\r"
  7.             ) {
  8.         txt=txt.substring(1,txt.length-1);
  9.     }
  10.     return txt;
  11. }
  12. //usage example:
  13. trace(lTrim("   here's a text to trim"));// outputs : here's a text to trim

Pretty much straight forward, the function accepts a string as argument and returns a string, it checks whether the first character is a space, tab, or newline character and simply cuts it out and runs the same check on the resulting substring until there are no white spaces left at the leftmost end of the string.

Now for the slightly harder rTrim function,

Actionscript:
  1. function rTrim (txt:String):String {
  2.    
  3.     while (txt.charAt(txt.length-1)==" " ||txt.charAt(txt.length-1)=="\t" || txt.charAt(txt.length-1)=="\n" || txt.charAt(txt.length-1)=="\r"){
  4.         txt=txt.substring(0,txt.length-1);
  5.     }
  6.     return txt;
  7.    
  8. }
  9. trace(rTrim ("rtrim this please  \n\r       ")+"delimiter");//outputs : rtrim this pleasedelimiter

The logic is very similar, feel free to use these wherever you like.
I would recommend using these as part of a class for string manipulation.
Btw, these functions are AS2 and AS3 compatible.

22
Apr

One More reason to hate Microsoft!

Posted By wassim in Wassim

Like many of you outlook express users, I got an email today informing me that outlook express will no longer be able to access hotmail accounts beyond June 30 because the geniuses at Microsoft have invented what they think is a better protocol and outlook doesn't support it so they had to come up with a new "magnificent" piece of shit called Windows Live Mail. Why not upgrade outlook express? Well they say it will take a lot of work to add support to the good old outlook express…As if making a new program from scratch is easier! Do they take us for fools or something? Well maybe so and for a reason, we still are using there OS!

Like a dumb ass, I believed this crap and went straight to the download page, installed and fired the application to be saluted by a crash, hmmm, typical Microsoft first run behavior.

Restarted the application and watched it at work, it seems it's using the same engine as outlook with the sole difference that it crashes every 3 to 5 minutes or so, well, Now I know why they had to put outlook aside, because it works and they simply can't withstand the idea of having an application or even an operating system that works without killing it for the sake of shitty new applications no one really wants or prefers over the existing ones…

Having that said, I am seriously considering switching to Linux, the knoppix compilation is really cool and I am waiting for the Linux version of Adobe flash to switch permanently to Linux, if anyone knows a way I can start using flash on a Linux, plz drop me a line.

20
Apr

paypal enabled mini mp3 player

Posted By wassim in Flash

An XML driven slick mp3 player with playlist support and paypal as payment gateway, the look and feel is clean crisp and WEB2.0.

The player displays album art and a nice spectrum analyzer animation and comes with two skins, the black and white ones.

Here's a preview of the players, click to see them in action:

23
Feb

actionScript AS2 (typewriter) text effect

Posted By wassim in Flash, Flash Tutorials

I needed a typewriter text effect with a twist for an mp3 player I was making, looked around and could not find one that suits my needs so I wrote this class, should do the job.

Actionscript:
  1. /*
  2. @author = Wassim Sidani
  3. @www.sidani.info
  4. usage example:
  5. var tE:TxtEff=new TxtEff(textFieldInstance, textToWrite, delay);
  6. textFieldInstance= a reference to a text field.
  7. textToWrite= the actual text that will be typed in the text field.
  8. delay = dealy in milliseconds before writing next character;
  9. */
  10. class TxtEff extends TextField
  11. {
  12.     function TxtEff (me, txt, delay)
  13.     {
  14.         //clearInterval(myInt);
  15.         //clearTimeout(myOtherIn);
  16.         myClass=this;
  17.         inite (me, txt, delay);
  18.     }
  19.     function inite (me, txt, delay)
  20.     {
  21.        
  22.         var j : Number = 0;
  23.         chars = ['$', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', ' '];
  24.         var initialText : String = txt;
  25.         for (k = 0; k <txt.length; k ++)
  26.         {
  27.             me.replaceText (k, k + 1, '-');
  28.         }
  29.         var myInt : Number = setInterval (go, delay, me);
  30.         function go (me)
  31.         {
  32.             //trace('goo is called and me.text ='+me.text);
  33.             if (j <initialText.length)
  34.             {
  35.                 //trace('j is ' + j+" and chars.length is "+chars.length);
  36.                 for (var i = 0; i <chars.length; i ++)
  37.                 {
  38.                     if (initialText.charAt (j) == chars [i])
  39.                     {
  40.                         me.replaceText (j, j + 1, chars [i]);
  41.                         j ++;
  42.                         break;
  43.                     }
  44.                 }
  45.             } else
  46.             {
  47.                 clearInterval (myInt);
  48.                 trace ("done j=" + j);
  49.                 //myOtherIn=setTimeout(myClass.inite,3000,me,txt,delay);
  50.             }
  51.         }
  52.     }
  53.    
  54. }

13
Jan

Flash shopping cart

Posted By wassim in Flash

The best flash shopping cart you've ever seen!

The flash cart supports multiple categories of products; it is driven by XML or a mySQL database.

The flash shopping cart was designed with usability in mind, it loads and is ready to go in less than 10 seconds! Faster than html or php based carts!

User friendly, highly flexible, lightweight (around 120 kb!) and a cool web 2.0 design are not the whole deal, there's more, a lot more!

Seamless paypal integration, the purchase is itemized and you get to see the details about each item in the paypal interface.

The merchant paypal account is easily customizable; you can set the paypal address, currency, thankYouUrl and cancelUrl.

The mySQL version is equipped with an admin panel that makes cart management, including thumbs and full size pictures upload a breeze even to non techy users.

This flash shopping cart is robust, it supports a variety of formats, can display jpg, png, gif and even swf pictures (both thumbnails and sull size pictures) of your products. It's simply an all-in-one solution.

A demo of this flash shopping cart is available here.