Flex3 Class Loader myclassloader.

Source: Internet
Author: User

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 {}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.