Array Arithmetic

by Highly forked from text and timer (diff: 76)
♥0 | Line 63 | Modified 2013-12-06 06:53:24 | MIT License
play

ActionScript3 source code

/**
 * Copyright Highly ( http://wonderfl.net/user/Highly )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lvmq
 */

// forked from Highly's text and timer
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.Event;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            //output declaration
            var out1:TextField = new TextField();
            out1.x=0;
            out1.y=0;
            out1.selectable = false;
            out1.multiline = true;
            out1.wordWrap = true;
            out1.width = stage.stageWidth;
            out1.height = stage.stageHeight;
            out1.text = "hi";
            addChild(out1);
            //end of output declaration
            var ti:Timer = new Timer(20,0);
            ti.addEventListener(TimerEvent.TIMER,tmr);
            //ti.start();
            var test:String = "0";
            out1.text = "fuck";
            var tArr:Array = new Array();
            tArr = numToArr(test);
            for(var i:int = 0; i< tArr.length;++i){
                out1.appendText("\n"+tArr[i]);
            }


            function tmr(e:TimerEvent):void{
                
                
            }
            function addNum(num1:Array, num2:Array):Array{
                var arr:Array = new Array();//return array
                var n1:Array = new Array();
                var n2:Array = new Array();
                var carry:int = 0;
                //set n1 and n2 according to size (bigger input -> n1, smaller input -> n2)
                if(num1.length>=num2.length){
                    n1 = num1;
                    n2 = num2;
                }else{
                    n1 = num2;
                    n2 = num1;
                }
                for(var i:int = n2.length-1; i>=0; --i){
                    
                }

                return arr;

            }

            //Numbers will be stored as arrays with the leftmost number being the first element of the new array
            function numToArr(num:String="0"):Array{
                //defining the offset for determining characters
                var offset:int = String("0").charCodeAt(0);
                var arr:Array = new Array();
                var tn:int;//temporary input integer storage
                for(var i:int = 0; i<num.length; ++i){
                    tn = num.charCodeAt(i)-offset;
                    if(tn<0||tn>9){
                        arr.push("ERR: Invalid Input (valid: 0-9)");
                        return arr;
                    }else{
                        arr.push(tn);
                    }
                }
                return arr;
            }
        }
    }
}