fontSize="26" fontWeight="bold" />
<spacer height="20"></spacer>
<hbox><br><button label="Hello" click="helloHandler()"></button> <br><button label="GoodBye" click="goodByeHandler()"></button> <br></hbox>
You have to register classes to Singleton before you use it. About Mixin metadata, See
The [Transient] and [Mixin] metadata tags.
在使用之前,你必须将你的类注册到singleton至于MIXIN元标签,可以参看相应的链接
org.pepe.managers.AppBootstrap (AS3)
- packageorg.pepe.managers
- {
- importflash.utils.getDefinitionByName;
-
- importmx.core.Singleton;
- importmx.managers.ISystemManager;
- importmx.utils.ObjectUtil;
-
- [Mixin]
- publicclassAppBootstrap
- {
-
-
- publicstaticfunctioninit(sm:ISystemManager):void
- {
-
- trace(ObjectUtil.toString(sm.info()));
-
-
- Singleton.registerClass(
- "org.pepe.managers::HogeManager",
- Class(getDefinitionByName("org.pepe.managers::HogeManager"))
- );
- Singleton.registerClass(
- "org.pepe.managers::FooManager",
- Class(getDefinitionByName("org.pepe.managers::FooManager"))
- );
- }
- privatevar_hoge:HogeManager;
- privatevar_foo:FooManager;
- publicfunctionAppBootstrap()
- {
- super();
- }
- }
- }
org.pepe.managers.HogeManager (AS3)
- packageorg.pepe.managers
- {
- importflash.events.EventDispatcher;
- importflash.events.IEventDispatcher;
-
- importmx.controls.Alert;
- publicclassFooManagerextendsEventDispatcherimplementsIFooManager
- {
- privatestaticvar_instance:FooManager;
-
-
- publicstaticfunctiongetInstance():FooManager
- {
- if(!_instance){
- _instance=newFooManager();
- }
-
- return_instance;
- }
- publicfunctionFooManager(target:IEventDispatcher=null)
- {
- super(target);
- }
-
- publicfunctionsayGoodBye():void
- {
- Alert.show("GoodBye","FooManager");
- }
-
- }
- }
You have to add compiler option like below.
"-load-config+=config/custom-config.xml"
你必须加上上面的这行编译器选项
custom-config.xml
<?xml version=<SPAN style="COLOR: #0000ff">"1.0"?>
<flex-config xmlns="<SPAN" style="COLOR: #0000ff">"<a href="http://www.adobe.com/2006/flex-config" target="_blank">http://www.adobe.com/2006/flex-config</a>"><br><br><span style="COLOR: #000080"><symbol></symbol></span>org.pepe.managers.AppBootstrap<span style="COLOR: #000080"></span><br><span style="COLOR: #000080"><span style="COLOR: #ff8000"></span></span><br></flex-config>
SingletonSampleForFlex2
source of SingletonSampleForFlex2
SingletonSampleForFlex3
source of SingletonSampleForFlex3
BTW, on Japanese environment, css definition of source view is output
in Japanese. Therefore, source view doesn't work correctly.
本文转自
http://shigeru-nakagaki.com/index.cfm/2007/12/19/20071220-How-to-use-mx-core-Singleton