【翻译】How to use mx.core.Singleton (Flex2.0.1/Flex3)



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)




  1. packageorg.pepe.managers

  2. {

  3. importflash.utils.getDefinitionByName;


  4. importmx.core.Singleton;

  5. importmx.managers.ISystemManager;

  6. importmx.utils.ObjectUtil;


  7. [Mixin]

  8. publicclassAppBootstrap

  9. {


  10. //SystemManagercallthisfunction

  11. //beforeApplicationinitialize

  12. publicstaticfunctioninit(sm:ISystemManager):void

  13. {

  14. //setabreakpointhereandtrytodebug:)

  15. trace(ObjectUtil.toString(sm.info()));


  16. //registerClassinfotoSingletonclass

  17. Singleton.registerClass(

  18. "org.pepe.managers::HogeManager",

  19. Class(getDefinitionByName("org.pepe.managers::HogeManager"))

  20. );

  21. Singleton.registerClass(

  22. "org.pepe.managers::FooManager",

  23. Class(getDefinitionByName("org.pepe.managers::FooManager"))

  24. );

  25. }



  26. privatevar_hoge:HogeManager;//forcompiler

  27. privatevar_foo:FooManager;//forcompiler


  28. publicfunctionAppBootstrap()

  29. {

  30. super();

  31. }


  32. }

  33. }




org.pepe.managers.HogeManager (AS3)




  1. packageorg.pepe.managers

  2. {

  3. importflash.events.EventDispatcher;

  4. importflash.events.IEventDispatcher;


  5. importmx.controls.Alert;


  6. publicclassFooManagerextendsEventDispatcherimplementsIFooManager

  7. {

  8. privatestaticvar_instance:FooManager;


  9. //Singletoncallthisfunction

  10. publicstaticfunctiongetInstance():FooManager

  11. {

  12. if(!_instance){

  13. _instance=newFooManager();

  14. }


  15. return_instance;

  16. }



  17. publicfunctionFooManager(target:IEventDispatcher=null)

  18. {

  19. super(target);

  20. }


  21. publicfunctionsayGoodBye():void

  22. {

  23. Alert.show("GoodBye","FooManager");

  24. }


  25. }

  26. }




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="&lt;SPAN" style="COLOR: #0000ff">"<a href="http://www.adobe.com/2006/flex-config" target="_blank">http://www.adobe.com/2006/flex-config</a>"&gt;<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

你可能感兴趣的:(xml,css,Flex,Flash,Adobe)