Author Archives: Zevan

substr() Remove First Character

CLICK HERE TO COPY
Actionscript:

var someString:String = "_file";

trace(someString.substr(1));

/*

ouptuts:

file

*/

Turns out the second argument of substr() is optional..... not sure how I never noticed that before.

Posted in string manipulation, strings | Tagged , | Leave a comment

Is This swf Online?

CLICK HERE TO COPY
Actionscript:

private var _correctPath:String;

 

//.... somewhere a little later

 

 if (root.loaderInfo.url.split("http://").length == 1){

        _correctPath = "http://www.mywebsite.com/this/is/an/absolute/path/";

    }else{

        _correctPath = "";

    }

I like to do something like this when I'm working locally... it automatically tells my swf to use an absolute path for php files, xml files etc.... [...]

Posted in misc | Tagged , | 4 Comments

The Big init() #2

CLICK HERE TO COPY
Actionscript:

// see previous post for details, this code won't run on it's own

with(addChild(window)){

    x = 10, y = 10;

    with(addChild(c0)) x = 10, y = 10;

    with(addChild(c1)) x = 20, y = 10;

    with(addChild(box)){

        x = 50, y = 10;

        with(addChild(txt)) x [...]

Posted in misc | Tagged , | Leave a comment

The Big init() (nesting DisplayObjects)

CLICK HERE TO COPY
Actionscript:

function nest(top:DisplayObjectContainer, structure:Array):void{

       var p:DisplayObjectContainer;

       var key:String;

       for (var i:int = 0; i<structure.length; i++){

               if (structure[i] is DisplayObjectContainer){

                    p = structure[i];

                    if [...]

Posted in misc | Tagged , | Leave a comment