Making a messenger design pattern in as3 should not be too hard:
Seeing that this is possible:
function doStuff():void
{
trace("doStuff called");
}
var obj:Object = new Object();
obj["x"] = 100;
trace(obj.x);
obj["f"] = doStuff;
obj.f();
obj["f"]();
var fString:String = "f";
obj[fString]();
//output:
//100
//doStuff called
//doStuff called
//doStuff called
Showing posts with label Research. Show all posts
Showing posts with label Research. Show all posts
Wednesday, September 5, 2012
Messenger and Interpreter Pattern AS3
Thursday, March 22, 2012
Blitting Research
//Blitting Research.
//Used on a file with 3 objects on stage
//that are exported for actionscript:
//They Are:
//[1]:
//Instance S1 on stage:
//Exported as class: "SYM01"
//[2]:
//Instance "S1_copy" on stage:
//Is the SAME symbol in library
//as "S1". Thus should have the
//same .constructor result.
//[3]:
//Instance "S2" on stage:
//Exported as class: "SYM02"
//Theory behind research:
//I want to take movieClips embedded
//on stage or actual classes and pass
//them to my blit constructor.
//The blit constructor will look
//at if the object's class is already
//in the master static vector
//for the class. If it already exists,
//the blitter class will make the
//new bitmap an instance of a bitmap
//data object already in memory.
import flash.utils.Dictionary;
import flash.display.Bitmap;
import flash.display.BitmapData;
var kDict:Dictionary = new Dictionary();
//get class:
var c:Class = S1.constructor;
kDict[c] = 1;
//see if it exists:
if( kDict[c] != null ){
trace("Test Pass");
}else{
trace("FAIL");
}
//get another class that does NOT
//exist in dictionary:
var d:Class = S2.constructor;
if( kDict[d] != null ){
trace("FAIL");
}else{
trace("Test Pass");
}
//get another instance on the screen
//that has also been exported for actionscript,
//but this one is of the SAME
//class as variable "c".
var c2:Class = S1_Copy.constructor;
if( kDict[c2] != null ){
trace("Test Pass");
}else{
trace("FAIL");
}
trace("end of script");
Thursday, February 23, 2012
Object type can work like dictionary as3
//Did not know this could be done:
var mc:MovieClip = new MovieClip();
mc["x"] = 0; //works like mc.x
mc["y"] = 0; //works like mc.y
//Also, while trying to make a function to put objects in a "global dictionary",
//I realized that... I need an "Object" instance... not a "Dictionary" instance.
var obj:Object = new Object();
obj["kay"] = "123"; //store value
obj["pika"] = mc; //store object
var mc:MovieClip = new MovieClip();
mc["x"] = 0; //works like mc.x
mc["y"] = 0; //works like mc.y
//Also, while trying to make a function to put objects in a "global dictionary",
//I realized that... I need an "Object" instance... not a "Dictionary" instance.
var obj:Object = new Object();
obj["kay"] = "123"; //store value
obj["pika"] = mc; //store object
Friday, February 10, 2012
x>0 faster than x==0
My assumptions where correct.
Checking to see if x>0 only requires checking 2 of the bits in the uint,
while checking to see x==0 requires checking ALL bits.
Checking to see if x>0 only requires checking 2 of the bits in the uint,
while checking to see x==0 requires checking ALL bits.
Bit Shift Populate Speed As3
Note on populating a uint's bits:
The shifting left(<<) method is faster than the shift right(>>>) method.
(>>>) is faster than (<<), but setting the LEAST significant bit is
faster than setting the most significant bit.
theUint = theUint << 1;
theUint = theUint | 1;
theUint = theUint >>> 1;
theUint = theUint | mostSigBit; //Where mostSigBit = 0x80000000 DO NOT HARDCODE.
//Will be super slow if you do.
//Don't do this:
//theUint = theUint | 0x80000000;
Subscribe to:
Posts (Atom)