Recently, many common processing classes have been used for projects. Post them and share them. If there are any mistakes, please correct them and welcome to the discussion.
//////////////////////////////////////// ////////////////////////////////////////
//
// My system
// Copyright 2008-2009 my systems inconfigurated
// All Rights Reserved.
//
// Notice: My system permits you to use, modify, and distribute this file
// Langversion ActionScript 3.0
// Playerversion, flash 9.0
// Date: 2009-03-18 Keren
// QQ: 994251681
// MSN: keren1515@hotmail.com
//
//////////////////////////////////////// ////////////////////////////////////////
// Flex Class Loader
Package org. App. utils. Common
{
Import flash. utils .*;
Import MX. Core. classfactory;
Public class myclassloader
{
Private Static Var instance: myclassloader = NULL;
Public static function getinstance (): myclassloader {
If (instance = NULL ){
Instance = new myclassloader (New singletonenforcer ());
}
Return instance;
}
Public Function myclassloader (Enforcer: singletonenforcer)
{
If (enforcer = NULL) throw new error ("this class is singletonenforcer .");
}
//////////////////////////////////////// ////////////////////////////////
/**
* Load a class and set the attribute value for the class.
* Note: The target class should have a constructor with null parameters. If there is a parameter, I don't know how to pass it in. I haven't thought about it yet.
* @ Param targetclass the target class, which can be a string or a class name
* @ Param properties the attribute value of the target class, in the josn format, similar to {A: 'A', B: 12}
*
* @ Return object target Instance Object
*/
Public Function loadclassbyclass (targetclass: class = NULL, properties: Object = NULL): object {
Try {
VaR Cf: classfactory = new classfactory (targetclass );
Cf. properties = properties;
Return Cf. newinstance ();
} Catch (error: Error ){
Throw new error ("loading class loadclassbyclass () encountered an error." + error. Message );
}
Return NULL;
}
Public Function loadclassbyname (classname: String = NULL, properties: Object = NULL): object {
Try {
VaR CLS: class = loadasclass (classname );
VaR Cf: classfactory = new classfactory (CLS );
Cf. properties = properties;
Return Cf. newinstance ();
} Catch (error: Error ){
Throw new error ("loading class loadclassbyname () encountered an error." + error. Message );
}
Return NULL;
}
Public Function loadasclass (classname: string): Class {
Try {
// Convert class name to class object.
VaR CLS: class = getdefinitionbyname (classname) as class;
Return CLS;
} Catch (error: Error ){
Throw new error ("loading class loadasclass () encountered error." + error. Message );
}
Return NULL;
}
Public Function loadasobject (classname: string): object {
Try {
// Convert class name to class object.
VaR CLS: class = getdefinitionbyname (classname) as class;
// Create a new instance of the class.
Return new Cls ();
} Catch (error: Error ){
Throw new error ("loading class loadasobject () encountered error." + error. Message );
}
Return NULL;
}
//////////////////////////////////////// ////////////////////////////////
//////////////////////////////////////// ////////////////////////////////
} // End class
} // End package
Class singletonenforcer {}