Author Archives: Zevan

Multiton

CLICK HERE TO COPY
Actionscript:

package {

 

    public class Multiton {

       

        public var test:String = "";

       

        private static  var _okToCreate:Boolean;

        private static  var _instances:Object = new Object();

        private static var _instanceNum:int = 0;

 

        [...]

Posted in OOP | Tagged , | Leave a comment

Private Square Bracket Syntax

CLICK HERE TO COPY
Actionscript:

package {

   

    import flash.display.Sprite

   

    public class Test extends Sprite {

       

        private var _test:String = "private square brace syntax";

        public function Test(){

            trace(this["_test"]);

        }

    }

}

It's important to note [...]

Posted in Uncategorized | Tagged , | 1 Comment

Hill Climbing

CLICK HERE TO COPY
Actionscript:

var target:Array = ("actionsnippet").split("");

var leng:int=target.length;

var iterations:int = 0;

 

var alphabet:Array = ("abcdefghijklmnopqrstuvwxyz").split("");

var search:Array = randomString();

var indices:Array = new Array();

for (var i:int = 0; i<leng; i++) indices.push(i);

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

    for (var i:int = 0; i<10; i++){

        if (indices.length> 0){

           var ii:int = int(Math.random()*indices.length);

      [...]

Posted in arrays, misc, strings | Tagged , | 5 Comments

Previous and Next Buttons

CLICK HERE TO COPY
Actionscript:

var prevBtn:Sprite = makeArrow(100, 100);

prevBtn.rotation = 180;

var nextBtn:Sprite = makeArrow(130, 100);

 

var index:int = 0;

var vals:Array = [1,2,3,4,5,6,7,8,9,10,11];

var leng:int = vals.length;

 

trace(vals[index]);

 

prevBtn.addEventListener(MouseEvent.CLICK, onPrev);

function onPrev(evt:MouseEvent):void {

    index--;

    if (index <0){

        index = leng - 1;

    }

    trace(vals[index%leng]);

}

nextBtn.addEventListener(MouseEvent.CLICK, onNext);

function onNext(evt:MouseEvent):void {

    index++;

    trace(vals[index%leng]);

}

 

function makeArrow(xp:Number, yp:Number):Sprite {

    [...]

Posted in UI, misc | Tagged , | Leave a comment