you are here: codestackercodes [RSS] → tag actionscript [RSS]

ExternalInterface sample

import flash.external.ExternalInterface;
 
function alert() {
	ExternalInterface.call("alert", "Only a test");
}

mybt.onRelease = function(){
	alert();
}

full screen button

fullScreen_btn.onRelease = fullScreen_btn.onReleaseOutside = toggleFullScreen;
	fullScreen_btn.onRollOver = onRollOverHandler;
	fullScreen_btn.onRollOut = onRollOutHandler;

	function onRollOverHandler()
	{
	}

	function onRollOutHandler():Void
	{

	}

	function toggleFullScreen():Void
	{
		if( Stage["displayState"] == "normal"){
			goFullScreen();
		} else {
			exitFullScreen();
		}
	}
	function goFullScreen():Void
	{
		   Stage["displayState"] = "fullScreen";
	}

	function exitFullScreen():Void
	{
	   Stage["displayState"] = "normal";
	}

explode function like php

String.prototype.explode = function(separator:String) {
	var string = this;
	var list = new Array();

	if (separator == null) return false;
	if (string == null) return false;

	var currentStringPosition = 0;
	while (currentStringPosition<string.length) {
		var nextIndex = string.indexOf(separator, currentStringPosition);
		if (nextIndex == -1) break;
		var word = string.slice(currentStringPosition, nextIndex);
		list.push(word);
		currentStringPosition = nextIndex+1;
	}
	if (list.length<1) {
		list.push(string);
	} else {
		list.push(string.slice(currentStringPosition, string.length));
	}
	return list;
}

var mystring = "test1 - test2";
exploded = mystring.explode(" - ");
trace (exploded[0]); // returns 'test1'

remove all movieclips

a simple sample

// 3 solutions

for (var i in holder) {
    if(typeof(holder[i])=="movieclip" && holder[i]._name.substr(0,4)=="foo_") {
           holder[i].removeMovieClip();
    }
}

for (var i=0;i<noOfclips;i++) {
    var clip=_root["mc"+i];
    clip.removeMovieClip();
}

for (var n in this) { 
    removeMovieClip(this[n]); 
}
Displaying all 4 Code