RSS Feed for Actionscript 2Actionscript 2

Here it is…

Apollo has been released this morning in a alpha version. Download it here.


Apollo

Lynda has but up some tutorial video’s on Apollo already. Go check them out now

And here is a shared book, titled “Apollo for Adobe Flex Developers Pocket Guide” and it free for non commercial usage.

Saving in Flash or Flex

I’m running around with following thoughts quit some time now. Why can’t adobe build in save options in flash and flex? Is it because safety issues? I don’t think that would be an issue, cause the same can be achieved with javascript, c, java, php, and the rest you can sum up. Or is it because Apollo is being released soon and Adobe is hoping in a increase in popularity because this “feature” is probably supported in Apollo? I say build it in flash and flex so we don’t have to work with annoying 3th party software. And if someone can explain it to me why it isn’t build in, I would be happy to hear it, cause I would love to understand it.

Arguments, a piece of history?

Did you use the arguments object in actionscript 2? This vague object that you could call without having seen it anywere. Well it has gotten a lot better with Actionscript 3. They introduced the rest keyword.

This is how it works:

Actionscript:
  1. //Create a function with the rest keyword like : "... args"
  2. public function average (name:String, ... args):void{
  3.   var total:Number = 0;
  4.  
  5.   //Handle the rest keyword like an array
  6.   for(var i:Number=0; i<args.length; i++){
  7.     total += args[i];
  8.   }
  9.  
  10.   var avarage:Number = total / args.length;
  11.  
  12.   trace("The average of " +name +" is: " +average);
  13.   // traces: The average of Averagetest is: 2.75
  14.  
  15. }
  16.  
  17. // Just call the function with a name and a variable number of numbers
  18. average("Averagetest", 2,2,3,4);

I even tried the arguments Object in actionscript 3 but it was kinda buggy. So I just dropped that, the rest keyword works fine and you don't have to guess where it is coming from. Bye bye arguments.

Format text

When I was working on a flash application I came across a problem of a back-end who was returning strong tags...something flash still finds like it needs to be ignored when it is put in html text. So I wrote a static format class which could replace text with other text. So not only usable for html but also for other things you might want to replace. I rewrote the class to actionscript 3.

Actionscript:
  1. package{
  2.   public class FormatText{
  3.     private static function replace(sValue:String, sToReplace:String, sWith:String):String{
  4.       return sValue.split(sToReplace).join(sWith);
  5.     }
  6.    
  7.     public static function format(sValue:String):String{
  8.       //add your text that needs replacing here
  9.       //sValue = replace(sValue, <text that needs replacing>,<text that needs to be inserted>)
  10.       sValue = replace(sValue, "<strong>", "<b>");
  11.       sValue = replace(sValue, "<STRONG>", "<b>");
  12.       sValue = replace(sValue, "</strong>", "</b>");
  13.       sValue = replace(sValue, "</STRONG>", "</b>");
  14.        
  15.       sValue = replace(sValue, "<em>", "<i>");
  16.       sValue = replace(sValue, "<EM>", "<i>");
  17.       sValue = replace(sValue, "</em>", "</i>");
  18.       sValue = replace(sValue, "</EM>", "</i>");
  19.        
  20.       return sValue;
  21.     }
  22.   }
  23. }

View an example here.