By Zevan | February 9, 2009
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 [...]
By Zevan | February 8, 2009
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 [...]
By Zevan | February 7, 2009
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 actionscript, flash |
By Zevan | February 6, 2009
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);
[...]