Download De Monster Debugger here
Apologies for the speed, and there being no voice over but it’s pretty simple to follow. The video simply shows how to download, install and use with a simple Actionscript Project in Flex Builder 3.
as3 experiments,source,code,snuffyTHEbear, robert daniels, as3, actionscript, flash, air, blog, developer, freelance, buxton, derby
Download De Monster Debugger here
Apologies for the speed, and there being no voice over but it’s pretty simple to follow. The video simply shows how to download, install and use with a simple Actionscript Project in Flex Builder 3.
[Update: Updated the core class with functiosn to scramble text, get random characters from specific paramaters, also updated the example to show both Scramble and Unscramble in action, may post a live example]
Came accross this AS1 Tutorial, and decided to code my own class from scratch, came along nicely.
Scrambler.as: Download
Code:
package com.arcticcode.greenFlames.Text { public class Scrambler { public static const ALPHABET:String = "abcdefghijklmnolpqrstuvwxyz"; public static const NUMBERS:String = "0123456789"; public static const SYMBOLS:String = "`¬!\"£$%^&*()_+=-[];'#./,{}~@:?><\|"; public static function scramble(input:String):String { var str:String = ""; for(var i:uint = 0;i<input.length;i++) { str += getRanChar(input.charAt(i)); } return str; } public static function getRanChar(char:String):String { var ch:String = ""; if(ALPHABET.indexOf(char) != -1) { ch = ALPHABET.charAt(Math.floor(Math.random()*ALPHABET.length)); if(ch == char) { ch = getRanChar(char); } } else if(ALPHABET.indexOf(char.toLowerCase()) != -1) { ch = ALPHABET.charAt(Math.floor(Math.random()*ALPHABET.length)).toUpperCase(); if(ch == char) { ch = getRanChar(char); } } else if(NUMBERS.indexOf(char) != -1) { ch = NUMBERS.charAt(Math.floor(Math.random()*NUMBERS.length)); if(ch == char) { ch = getRanChar(char); } } else if(SYMBOLS.indexOf(char) != -1) { ch = SYMBOLS.charAt(Math.floor(Math.random()*SYMBOLS.length)); if(ch == char) { ch = getRanChar(char); } } else if(char == " ") { ch = " "; } return ch; } public static function unscramble(input:String,target:String,letters:Boolean,numbers:Boolean,symbols:Boolean,mixedCase:Boolean,...extraChars):String { var chars:String = ""; if(letters){chars += ALPHABET}; if(mixedCase){chars += ALPHABET.toUpperCase();} if(numbers){chars += NUMBERS;} if(symbols){chars += SYMBOLS;} if(extraChars != null){chars += extraChars;} var str:String = input; var ts:String = ""; var char:String = ""; for(var i:uint=0;i<str.length;i++) { NUMBERS.indexOf(target.charAt(i)) != -1 ? char = NUMBERS.charAt(Math.floor(Math.random()*NUMBERS.length)) : char = chars.charAt(Math.floor(Math.random()*chars.length)); str.charAt(i) != target.charAt(i) ? ts += char : ts += str.charAt(i); } return ts; } } }
To Use:
package { import com.arcticcode.greenFlames.Text.Scrambler; import com.arcticcode.greenFlames.utils.StringUtils; import flash.display.Sprite; import flash.events.Event; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; [SWF(width=600,height=400,backgroundColor=0xFFFFFF)] public class TextScramble extends Sprite { private var tf:TextField; private var targetString:String="My Text 2008"; private var count:uint = targetString.length; private var currString:String; private var arr:Array; private var char:String = ""; public function TextScramble() { init(); } private function init():void { tf = new TextField(); tf.autoSize = TextFieldAutoSize.LEFT; tf.defaultTextFormat = new TextFormat("Verdana",12,0); addChild(tf); tf.selectable = false; tf.text = " "; addEventListener(Event.ENTER_FRAME, loop); } private function loop(e:Event):void { tf.text = Scrambler.unscramble(tf.text, targetString, true, true, false, true, " "); tf.text == targetString ? removeEventListener(Event.ENTER_FRAME, loop) : null; } } }
I really need to stop playing with isometrics, more addictive than lego. Anyway made this from boredom.
Can you guess what it is? Post a comment if you know…
So there’s no built in method to truncate a number in actionscript. Well a bit of playing around and a simple work around is just as good.
As most of you will know String’s can be truncated via substr();.
Well just typecast your value to be truncated to a String, call the substr(), using the length of the string minus your amount of digits to trincated, then typecast it back to a Number.
Code:
1 2 3 4 | function truncate(val:String,truncCount:uint):String { return val.substr(0,val.length-truncCount); } |
To use:
1 2 3 4 | var num:Number = 56.673856; trace(num)//56.673856 num = Number(truncate(num.toString(),5)); trace(num)//56.6 |