Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Carlos www.abismo.com.br

Finding stuff in strings / or not!

Contains is an actionscript function that I use a lot. From Kirupa

contains = function (input, arrayData) {
  for (i=0; i<arrayData.length; i++) {
    if (arrayData[i] == input) {
      return 1;
    }
  }
  return -1;
};

POST and GET: Flash

Sends POST data to a webpage through flash.

var my_Var:LoadVars = new LoadVars();
my_Var.Variavel1 = Variavel1_txt.text;
my_Var.Variavel2 = Variavel2_txt.text;

/*"_self" specifies the current frame in the current window. 
"_blank" specifies a new window. 
"_parent" specifies the parent of the current frame. 
"_top" specifies the top-level frame in the current window. */

my_Var.send("URL_stays_here", "_blank", "POST");

Things I keep forgetting...


How to access something in the timeline dynamically:

this["whatever"+i]._x

//or

root["whatever"+i]._x

Random Numer

Random number function - returns a number between min and max
Receives (min, max)
Returns randomNum


function randRange(min:Number, max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return randomNum;
}

Actionscript

// Countdown code

countDown = function() {
	seconds_conta = seconds_conta - 1;
	hours = int(seconds_conta / 3600);
	minutes = int((seconds_conta / 60) - (hours * 60));
	//seconds = int(seconds_conta-((hours*3600)+minutes*60));
	seconds = int((seconds_conta % 60));
	
	//Se for menor que dez, acrescenta um zero
	if(minutes<10){
		minutes="0"+minutes;
	}
	if(seconds<10){
		seconds="0"+seconds;
	}
	
	//Será que precisa colocar no frame correto?
	timer_txt.text=(hours+":"+minutes+":"+seconds);
	
		//trace("seconds_conta: "+seconds_conta);
		//trace("hours: "+hours);
		//trace("minutes: "+minutes);
		//trace("seconds: "+seconds);
	
	if (seconds_conta == 0) {
          clearInterval(timer);
		  //Chama função de acabar a contagem!
		  //fim_das_questões();
     }
} 

///////// Acrescentar no código
//Tempo total inicial em segundos ->Calculado a partir da quantidade de questões
seconds_conta = 185;
///////// Inicia o timer
//A cada 1000 ms, ativa a função countDown, diminuindo um segundo do total
timer = setInterval(countDown, 1000);