Author Archives: Zevan

“in” Operator

CLICK HERE TO COPY
Actionscript:

var obj:Object = {name: "Joe", hobby: "Guitar", age:"80"};

 

if ("name" in obj){

    trace(obj, " has a name property");

}

 

if ("x" in obj == false){

    trace(obj, " doesn't have an x property");

}

 

 

var mySprite:Sprite = new Sprite();

 

if ("currentFrame" in mySprite == false){

    trace(mySprite, "does not have a currentFrame property");

}

The "in" operator can be [...]

Posted in Operators, dynamic | Tagged , | Leave a comment

Crackable String Encoding

CLICK HERE TO COPY
Actionscript:

var encode:Object = new Object();

var decode:Object = new Object();

var a:Array = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".split("");

 

// change this for different encoded results

var offset:int = 10;

 

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

    var index:int = (a.length - i - offset) % a.length;

    encode[a[i]] = a[index];

    decode[a[index]] = a[i];

}

 

function encodeString(str:String):String{

    return map(str, encode);

}

 

function [...]

Posted in OOP, strings | Tagged , | Leave a comment

Static Constructor / Initializer

CLICK HERE TO COPY
Actionscript:

package{

   

    public class Lookup{

       

        private static var _random:Array;

        // static initializer

        {

            trace("I am a static initializer for " + Lookup);

            init();

        }

  [...]

Posted in OOP | Tagged , | 1 Comment

Graphics Class Methods in XML

CLICK HERE TO COPY
Actionscript:

// for simplicity I left this XML inline, this will work exactly the same if it were external

var program:XML=<body>

                <draw>

                  <![CDATA[

                   beginFill(0xFF0000);

                [...]

Posted in Graphics, XML, dynamic, external data, functions, string manipulation, strings | Tagged , | Leave a comment