Archive for the ActionScript Category

In actionscript 3 how to remove duplicates from array

Posted by mahmud ahsan on April 21, 2010 in ActionScript | No Comments

actionscriptToday I was working in  actionscript 3 + php project. I was working in an array and I needed to remove duplicate entries from array. In php its very easy to remove duplicate entries.

There is a function in php named array_unique($array); that removes duplicate elements from array. So in php I could easily use

    $arr = array('a', 'b', 'a', 'c', 'd', 'b');
    $arr = array_unique($arr); //removes duplicate entries

But there is no such type of built in function in actionscript 3 for array. So I created my own function and used it

function removeDuplicate(arr:Array) : void{
    var i:int;
    var j: int;
    for (i = 0; i < arr.length - 1; i++){
        for (j = i + 1; j < arr.length; j++){
            if (arr[i] === arr[j]){
                arr.splice(j, 1);
            }
        }
    }
}

Now just call the function and pass an array

var arr:Array = new Array("a", "b", "a", "c", "d", "b");
removeDuplicate(arr);

splice(startIndex:int, deleteCount:uint); method removes elements from an array. So using 2 simple loops I solved my problem. But as my arrays are short 20 elements max so I don’t need to optimize this function.

reference: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html

Getting external parameters in ActionScript 3

Posted by mahmud ahsan on March 18, 2010 in ActionScript | 2 Comments

ActionScript 3.0

Actually this is not a big or complex post. I am a part time ActionScript 3.0 developer and recently in my company i2we, inc. I developed a customized jobs search widget for them. Where one of the criteria was when we include flash object in html, we can provide external parameter. Based on the parameter the flash widget customize its result.

So in this post, I will show how you can pass parameter from html and get them in your flash object. Please keep in mind that my code is based on ActionScript 3.0

Continue

Develop dynamic flash widget using PHP & ActionScript 3.0

Posted by mahmud ahsan on February 3, 2010 in ActionScript, Facebook, PHP | 3 Comments

flash_php_fb
Basically I’m mainly php base web application developer. But I have  much interest in ActionScript project. Sometimes when I get opportunity I work on it. Someday ago, I was assigned in a project, where I’ve to develop a Flash Widget using ActionScript 3.0 and php. This widget will be use mainly for facebook page.

So shortly the project requirements are:

  1. Develop a dynamic flash widget using ActionScript 3.0
  2. Communication between ActionScript and PHP API
  3. This widget should be working on any facebook page

To develop this project I’ve learned a new library called amfphp. Using this library its much easier and practical to communicate between ActionScript and php. In this article, I’ll show how to use amfphp and develop a dynamic flash widget.

Continue

Communication between Action Script 3.0 And Server

Posted by mahmud ahsan on October 23, 2008 in ActionScript, PHP | 5 Comments

Some days ago I developed a personal facebook application. In that application, I’ve to communicate between my flash (AS 3.0) game and my server. Now I’ve given the scenario I’ve faced:

Case 1: My target was to develop a dictionary and some simple word puzzle type games. And the application is for facebook.

Case 2: I developed and implemented the dictionary using FBJS (Facebook javascript). For data exchange format between FBJS and PHP I use JSON format (Really a lightweight format). Finally I implemented the dictionary perfectly.

Case 3: Now I chose to develop the games using FBJS. But the problem was, by seeing view source anyone could see the data come from PHP.  So, I decided to use Action Script 2.0 to develop the games. I know AS 2.0 very well but I found there are lot of changes (Core changes) in AS 3.0. So I decided to develop games using Flash Action Script 3.0. As I also want to learn the new trends of AS 3.0.

Case 4. Now I described the problem I faced to develop AS 3.0 games and to integrate them into facebook and how I solved them.

After succesfully developed the game, when data sent to flash from my server, there are 2 ways to do that from AS 3.0
Continue