Never been to DZone Snippets 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

About this user

rajesh

« Newer Snippets
Older Snippets »
Showing 1-10 of 18 total  RSS 

_Currentframe

var mCircle:MovieClip = mCircle;

trace(mCircle._currentframe); // Displays: 1
mCircle._currentframe = 6; // Will not take
trace(mCircle._currentframe); // Displays: 1

instanceof

var oFirstObject:Object = new Object();
var sStr:String = new String("Hai");
trace(oFirstObject instanceof Object);
trace(sStr instanceof String);

Dynamicaly placed buttons - duplicate movie clip

var myMC:MovieClip;
var i = 1;
var pad = 5;
while (i<6) {
trace(" i : "+i);
myMC.duplicateMovieClip("myMC"+i, i);
myMC.removeMovieClip();
this["myMC"+i]._x = this["myMC"+(i-1)]._x+(this["myMC"+(i-1)]._width)+pad;
this["myMC"+i].onRollOver = function() {
trace(this);
};
i++;
}

Set Time out function

function testMe() {
trace("callback: "+getTimer()+" ms.");
}

var intervalID:Number = setTimeout(testMe, 1000);

// clearTimeout(intervalID) // for clear the timeout

Check Internet Connected or not

var connected:Boolean = false;

function checkConnection():Void {
var myLoadVars:LoadVars = new LoadVars();

myLoadVars.onHTTPStatus = function(httpStatus:Number) {

if (httpStatus != 0) {
connected = true;
trace(connected);
} else {
connected = false;
trace(connected);
}

delete this;
};

myLoadVars.load("http://www.apple.com");
}

checkConnection();

Random Number

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

collapseWhiteSpace

function collapseWhiteSpace(theString:String):String
{
theString = theString.split("\r").join("");
theString = theString.split("\t").join("");
while ( theString.indexOf(" " ) != -1 ) {
theString= theString.split(" ").join(" ");
}
if (theString.substr(0,1) == " ") {
theString = theString.substr( 1 );
}
if (theString.substr( theString.length-1, 1 ) == " ") {
theString = theString.substr( 0, theString.length - 1 );
}
return(theString);
}

trace(collapseWhiteSpace("hai rajesh how are you"));

Concat two array

var sNames:Array = ["Rajesh","Buvanesh","Latha","Ramesh"];
var sPhones:Array = ["9940350708","00000000","044-42151184","9841026070"];

for (var i=0;i<sNames.length;i++){
trace(sNames[i]);
trace(sPhones[i]);
}

Array.push

var sEmployees:Array = [];
sEmployees.push(["Ramesh","9841026070"]);
sEmployees.push(["Rajesh","9940350708"]);
sEmployees.push(["Latha","044-42151184"]);
sEmployees.push(["Buvanesh","000-0000000"]);

for (var i:Number=0; i<sEmployees.length; i++){
trace("Name:" + sEmployees[i][0]);
trace("Phone:" + sEmployees[i][1]);
}

String to Array

var sEmployees:String = "Rajesh,Buvanesh,Latha,Ramesh";
var aEmployees:Array = sEmployees.split(",");
trace(aEmployees.toString());
« Newer Snippets
Older Snippets »
Showing 1-10 of 18 total  RSS