Asv3's Blog

April 28, 2010

Simple Form Submit in AS3

Filed under: actionscript, as3, flash — asv3 @ 6:04 pm

Here is the code one of my friend asked, he wanted flash to submit some data on click of a button. This script assumes you have a Movieclip with instance name “but1” on stage.

but1.addEventListener("click",submitContact);

function submitContact(e:Event) {
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("email.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.GET;
varSend.data = variables;
variables.Name="Ravi";
variables.Email="Ravi@Some.com";
varLoader.load(varSend)
}

October 17, 2009

Filtering Array For Objects with Unique values in ActionScript

Filed under: actionscript, flash, flex — Tags: , , , , , , — asv3 @ 8:33 am

I happened to go through many instances where I had to filter a flat list on given attribute for unique values. For example I have flat list of employees who is working in different territory with there achievements, problem is show the graph based on territory. In flex you can use GroupedColletion to achieve this, but if you doing it in flash you are left with no options other than Array.filter. Here is how I did it.

var flatData:Array = [

{ Region:"Southwest", Territory:"Arizona", Territory_Rep:"Barbara Jennings", Estimate:40000 , Actual:38865 },

{ Region:"Southwest", Territory:"Arizona", Territory_Rep:"Dana Binn", Estimate:30000 , Actual:29885 },

{ Region:"Southwest", Territory:"Central California", Territory_Rep:"Joe Schmoe" , Estimate:30000 , Actual:29134 },

{ Region:"Southwest", Territory:"Northern California" , Territory_Rep:"Lauren Ipsum" , Estimate:40000 , Actual:38805 },

{ Region:"Southwest", Territory:"Northern California" , Territory_Rep:"T.R. Smith" , Estimate:40000 , Actual:55498 },

{ Region:"Southwest", Territory:"Southern California" , Territory_Rep:"Jane Grove" , Estimate:45000 , Actual:44913 },

{ Region:"Southwest", Territory:"Southern California" , Territory_Rep:"Alice Treu" , Estimate:45000 , Actual:44985 },

{ Region:"Southwest", Territory:"Nevada" , Territory_Rep:"Bethany Pittman", Estimate:45000 , Actual:52888 }

];

 

// sort first to make sure filter logic doesn’t fail

flatData.sortOn("Territory");

// function to return true for false for filtering

function is_unique_ter(item:*, index:int, arr:Array) {

    if (index<arr.length1) {

        return item.Territory!=arr[index+1].Territory;

    } else {

        return true;

    }

 

}

 

//assign filtered data to different array

var filteredflatData:Array=flatData.filter(is_unique_ter);

 

// trace out contents of filteredflatData

for (var i:Object in filteredflatData) {

    var s="";

    for (var j:String in filteredflatData[i]) {

        s+=( filteredflatData[i][j])+",";

    }

    trace(s);

}

it should give trace output like this:

30000,Southwest,Arizona,29885,Dana Binn,
30000,Southwest,Central California,29134,Joe Schmoe,
45000,Southwest,Nevada,52888,Bethany Pittman,
40000,Southwest,Northern California,55498,T.R. Smith,
45000,Southwest,Southern California,44913,Jane Grove,

Create a free website or blog at WordPress.com.