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

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

Single-Line commenting in Actionscript with Textmate

- open the bundle editor and select the Actionscript bundle
- use the add button to make a new preference item, give it a scope of source.actionscript
- name it whatever
- paste in the following:

{   shellVariables = (
        {   name = 'TM_COMMENT_START';
            value = '// ';
        },
    );
}


- that's it! got these instructions on IRC from Infininight: http://pastie.textmate.org/private/clmfldbv2sexjcd7u6qjw

AS3 FlashVars equivalent: LoaderInfo

// Add this to your package..
import flash.text.*;

// And throw this in wherever..
var t:TextField = new TextField();
t.autoSize = TextFieldAutoSize.LEFT;
t.border = true;
addChild(t);

t.appendText("params:" + "\n");
try {
var key:String;
var val:String;
var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (key in flashvars) {
val = String(flashvars[key]);
t.appendText("\t" + key + ":\t" + val + "\n");
}
} catch (error:Error) {
t.appendText(error);
}

Make AS3 clips turn cursor into a hand on rollover..

  buttonMode = true; 
  mouseChildren = false;

AS3 SwapDepths Equivalent

function move_to_top() {
  // This will move the current object to the topmost z-index
  parent.setChildIndex(this, parent.numChildren-1);
}

PHP for removing www from request and redirecting. (Useful for System.security.allowDomain issues)

<?
	// if www.domain.com, redirect to domain.com
	if (strtolower(substr($_SERVER['HTTP_HOST'], 0, 3)) == "www") {
		header("Location: http://rgcreative.com" . $_SERVER['REQUEST_URI']);
	}
	
	// Full path to current URL (including query string)
	//echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>

Embedded Fonts in Modules

How to use embedded fonts in modules and late-load the embedded font.
Save TrueType font file as ./Arial.ttf
@font-face {
        src:url("./Arial.ttf");
        font-family: myFont;
}

Application
{
	font-family: 	myFont;
	font-size: 	10px;
}

Actionscript Perpetual easing

MovieClip.prototype.ease = function(prop, target, speed) {
	delta = this['_' + prop] - target;
	if (delta != 0) {
		this['_' + prop] = this['_' + prop] - (delta / speed);
		delta = this['_' + prop] - target;
		if (delta < .25 and delta > -.25) {
			this['_' + prop] = target;
			delta = 0;
		}
	}
};

flash date comparison

// well it's flash ...
cmpDat = new Array(2007,   12,     2,    0,  0,   0);
/*                 year    mon     day   hr  min  sec
*/

function compareDates(cmpDat){
	var jd:Date = new Date();
	var zd:Date = new Date(cmpDat[0], cmpDat[1]-1, cmpDat[2], cmpDat[3], cmpDat[4], cmpDat[5], 0);
	if(zd.getTime()<jd.getTime()){
		return true;
			} else {
		return false;
	}
}
// the time is now? (true / false)
if(compareDates(cmpDat)){
	trace('ok das wars dann');
}

help on "if" actionscript

hei,, i dont know if you have the time to answer me this questions, but i'm a little bit deseperated....

i have this script:


var arreglo3:String =_root.btn3admintitle;

var arreglo4:String =_root.btn4minsidetitle;

var arreglo5:String =_root.btn5systemtitle;


if(arreglo3 == "falso"){
_root.btn3.titu.text = arreglo3;
}
else{
_root.mainMenu.peliMovie.attachMovie("btn3admin", "btn3adminvideo", this.getNextHighestDepth(), {_x:5, _y:18});
}



if(arreglo4 == "falso"){
this.btn4.titu.text = arreglo4;
}
else{
this.mainMenu.peliMovie.attachMovie("btn4minside", "btn4minsidevideo", this.getNextHighestDepth(), {_x:5, _y:54});
}


if(arreglo5 == "falso"){
this.btn5.titu.text = arreglo5;
}
else{
this.mainMenu.peliMovie.attachMovie("btn5system", "btn5systemvideo", this.getNextHighestDepth(), {_x:5, _y:92});
}



what i want to do is to evaluate several times different variables, wheter if they are = to "falso" or to ather string,

The problem is that when the script runs it only read the last script... the last "if"... how can i make it to read all the 3 "if's"...?? or more?....

thanks

alejandro

Pass JSON to Flash's ExternalInterface

var json : String =
	"{a: 1, b: 'hello world', c: [1, 3, 4, 5]}";

var o : Object =
	ExternalInterface.call("function(){return " + json + ";"}");


The variable o should now contain an object representation of the string json.
Stolen from http://blog.iconara.net/2007/01/20/parsing-json-using-externalinterface/
« Newer Snippets
Older Snippets »
Showing 1-10 of 37 total  RSS