firestar
12-08-2003, 11:36 PM
Hi,
I am working on a Error Message Class, SeErrorMsg, that will allows me to read the error number and error msg from a text file and into a static hash array. The error number will be the "Key", and the error msg will be the "Value". I seem to have no problem of referencing the hash array, since I am able to print out the error msg by stating the following the inside the static function,initialized() , of the Error Message Class: trace("_aErrorMsg["+sKey+"]= " + _aErrorMsg[sKey]);
However, when I reference the hash arrary from the first frame of my errorTest.fla or inside a diffrent class in the following manner: trace(SeErrorMsg._aErrorMsg["e0001"]);
The trace display "undefined". I am baffled about this issues, I think it might be a timing issue, please help me on how to resolve it.
Please see my Error Class,
// Define Error Message class SeErrorMsg
// In SeErrorMsg.as:
class com.abc.seerror.SeErrorMsg {
static var _aErrorMsg:Array = new Array();
//static var _aErrorMsg:LoadVars = new LoadVars();
//constructor
function SeErrorMsg() { }
static function initialized():Boolean{
var loadSeErrMsg:LoadVars = new LoadVars();
var locale:String = "us";
//var path:String = "";
loadSeErrMsg.load(locale+"SeErrMsg.txt");
loadSeErrMsg.onLoad = function(success){
var obj:LoadVars = new LoadVars();
obj = this;
var sKey:String = "";
var sValue:String = "";
if (success) {
for (var properties:String in obj) {
if (properties != "onLoad" && properties != undefined) {
sKey = properties;
// trace ("skey " + sKey instanceof String);
sValue = obj[properties];
setErrMsg(sKey, sValue);
// trace("_aErrorMsg["+sKey+"]= " + getErrMsg(sKey));
trace("_aErrorMsg["+sKey+"]= " + _aErrorMsg[sKey]);
}
} // end of for loop
} else {
trace ("not loaded");
} // end of if(success)
} //end of onload
return true;
/**
_aErrorMsg["0001"] = "Invalid Email";
_aErrorMsg["0002"] = "The field name(s) can't be left empty";
_aErrorMsg["0003"] = "Please enter the password";
_aErrorMsg["0004"] = "Database connection error";
**/
}
static function setErrMsg(sEnum:String, sEmsg:String) {
_aErrorMsg[sEnum] = sEmsg;
}
static function getErrMsg(sEnum:String):Array {
return _aErrorMsg[sEnum];
}
static function get_aErrMsgs():Array {
return _aErrorMsg;
}
}
Here is my code in testErro.fla
import com.abc.seerror.*;
// Function: main()
// Desc: The single entry point for the application
var _aErrorMsg:Array = new Array(this);
SeErrorMsg.initialized();
_aErrorMsg = SeErrorMsg.get_aErrMsgs();
//trace(SeErrorMsg._aErrorMsg["e0001"]);
trace(_aErrorMsg["e0001"]);
for (var sKey:String in _aErrorMsg) {
trace(_aErrorMsg[sKey]);
}
Here is the content of my text file, usSeErrMsg.txt
e0001=Invalid Email&e0002=Please enter password
Thanks for your help
Please use the proper code syntax to format the code.
Read this page (http://www.actionscript.org/forums/misc.php3?action=bbcode#buttons) to find out more about the tag information.
Using this feature will assist people in reading and understanding your code and hopefully help you get better assistance. Best of all, it's easy to use; all you have to do is enter your code between a [ as ] tag and a [ /as ] tag. For example, try [ as ]trace("This is a test");[ /as ](Get rid of the space between the open/close brackets('[' and ']')
I am working on a Error Message Class, SeErrorMsg, that will allows me to read the error number and error msg from a text file and into a static hash array. The error number will be the "Key", and the error msg will be the "Value". I seem to have no problem of referencing the hash array, since I am able to print out the error msg by stating the following the inside the static function,initialized() , of the Error Message Class: trace("_aErrorMsg["+sKey+"]= " + _aErrorMsg[sKey]);
However, when I reference the hash arrary from the first frame of my errorTest.fla or inside a diffrent class in the following manner: trace(SeErrorMsg._aErrorMsg["e0001"]);
The trace display "undefined". I am baffled about this issues, I think it might be a timing issue, please help me on how to resolve it.
Please see my Error Class,
// Define Error Message class SeErrorMsg
// In SeErrorMsg.as:
class com.abc.seerror.SeErrorMsg {
static var _aErrorMsg:Array = new Array();
//static var _aErrorMsg:LoadVars = new LoadVars();
//constructor
function SeErrorMsg() { }
static function initialized():Boolean{
var loadSeErrMsg:LoadVars = new LoadVars();
var locale:String = "us";
//var path:String = "";
loadSeErrMsg.load(locale+"SeErrMsg.txt");
loadSeErrMsg.onLoad = function(success){
var obj:LoadVars = new LoadVars();
obj = this;
var sKey:String = "";
var sValue:String = "";
if (success) {
for (var properties:String in obj) {
if (properties != "onLoad" && properties != undefined) {
sKey = properties;
// trace ("skey " + sKey instanceof String);
sValue = obj[properties];
setErrMsg(sKey, sValue);
// trace("_aErrorMsg["+sKey+"]= " + getErrMsg(sKey));
trace("_aErrorMsg["+sKey+"]= " + _aErrorMsg[sKey]);
}
} // end of for loop
} else {
trace ("not loaded");
} // end of if(success)
} //end of onload
return true;
/**
_aErrorMsg["0001"] = "Invalid Email";
_aErrorMsg["0002"] = "The field name(s) can't be left empty";
_aErrorMsg["0003"] = "Please enter the password";
_aErrorMsg["0004"] = "Database connection error";
**/
}
static function setErrMsg(sEnum:String, sEmsg:String) {
_aErrorMsg[sEnum] = sEmsg;
}
static function getErrMsg(sEnum:String):Array {
return _aErrorMsg[sEnum];
}
static function get_aErrMsgs():Array {
return _aErrorMsg;
}
}
Here is my code in testErro.fla
import com.abc.seerror.*;
// Function: main()
// Desc: The single entry point for the application
var _aErrorMsg:Array = new Array(this);
SeErrorMsg.initialized();
_aErrorMsg = SeErrorMsg.get_aErrMsgs();
//trace(SeErrorMsg._aErrorMsg["e0001"]);
trace(_aErrorMsg["e0001"]);
for (var sKey:String in _aErrorMsg) {
trace(_aErrorMsg[sKey]);
}
Here is the content of my text file, usSeErrMsg.txt
e0001=Invalid Email&e0002=Please enter password
Thanks for your help
Please use the proper code syntax to format the code.
Read this page (http://www.actionscript.org/forums/misc.php3?action=bbcode#buttons) to find out more about the tag information.
Using this feature will assist people in reading and understanding your code and hopefully help you get better assistance. Best of all, it's easy to use; all you have to do is enter your code between a [ as ] tag and a [ /as ] tag. For example, try [ as ]trace("This is a test");[ /as ](Get rid of the space between the open/close brackets('[' and ']')