How to get variables from a URL using Javascript

How to get variables from a URL using javascript.

// ex url: http://www.example.com/index.html?hello=bonjour&goodevening=bonsoir
var hash = getUrlVars();
alert(hash['hello']); // prints 'bonjour'
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
Posted in Javascript | Tagged , , | Leave a comment

AJAX function using jquery

Jquery ajax function

var ajax = {
    go: function(type, url, data, callback) {
		$.ajax({
			type: type,
			url: url,
			data: data,
			success: function(msg){
				callback(msg);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert(errorThrown);
			}
		});
    }
};
Posted in Javascript, Jquery | Tagged , , , , | Leave a comment

AS3 switch statement using a string

Simple switch statement in ActionScript 3

var action:String = "addOption";
switch(action){
	case "addOption":
		//Code here
		break;
	case "removeOption":
		//Code here
		break;
	default:
		//Default code here
}
Posted in ActionScript 3.0 | Tagged , , , | Leave a comment

Searching through an array in AS3

Search for a value in Actionscript 3.

var myArray = new Array("bob", "jimmy", "sue");
var searchForJimmy = function (searchValue) {

trace("searching for: "+searchValue+" array length: "+myArray.length);

for (var i=0; i < myArray.length;i++)
{
   if (searchValue == myArray[i]) {
      trace("found "+searchValue+" at array # "+i);
   }
}
}
Posted in ActionScript 3.0 | Tagged , , , , | Leave a comment

For loop in actionscript 3

Example of a for loop in ActionScript 3. Enjoy

for (var i:Number = 0; i < image.length; i++){
	addChild(image[i]);
	image[i].x = (50*i);
}
Posted in ActionScript 3.0 | Tagged , , , , | Leave a comment

Calling a function from javascript to actionscript 3

Calling a function from Javascript to Flash / ActionScript 3.

//Javascript----------
function flashCom(flashIDName, stringVar){
   var video = (isIE()) ? window[flashIDName] : document[flashIDName];
   video.updateFlash(JSONString);
}
flashCom("flash_object_id_name", "string_to_be_passed");
//AS3----------------
package com{
   import flash.external.ExternalInterface;
   public class init extends MovieClip {
      public function init():void {
         ExternalInterface.addCallback("updateFlash", updateProject);
      }
      public function updateProject(msg:String){
         //code here
      }
    }
}
Posted in ActionScript 3.0, Javascript | Tagged , , , , | Leave a comment