Wednesday, February 6, 2013
Reference static class via variable
//Wanted to know if I could store a reference to a "registry"/"global container" inside of another class.
//This test proves it is possible.
//BUT, my auto-complete does not work on levelReg variable.
//NOTE: LevelReg (with capital "L") is the registry.
// levelReg (no capital "L" ) is the variable storing reference to the registry.
var levelReg:Class = LevelReg;
var levelNum:int = levelReg.currentLevelNumber;
trace("levelNum==" + levelNum);
levelReg.currentLevelNumber -= 4;
levelNum = levelReg.currentLevelNumber;
trace("levelNum==" + levelNum);
UPDATE:
"hasOwnProperty" works on reference as well:
if (levelReg.hasOwnProperty("currentLevelNumber") ) { trace("we have a currentLevelNumber prop"); }
if (!levelReg.hasOwnProperty("super peanutcats ") ) { trace("no super peanutcats");}
Output:
we have a currentLevelNumber prop
no super peanutcats
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment