programming Flex2 ѧϰ±Ê¼Ç£µÚ5Õ£¿ò¼Ü»ù´¡.txt
(2007-11-26 21:38)
µÚ5ÕÂ
Framework Fundamentals¿ò¼Ü»ù´¡
Àí½âFlexÓ¦ÓóÌÐòµÄÉúÃüÖÜÆÚ
FlexÓ¦ÓõĸùÊÇSystemManger£¬ËüÊÇflash.display.MovieClipµÄ×ÓÀ࣬һ¸öFlash PlayerÏÔʾ¶ÔÏóÀàÐÍ¡£SystemManagerÓÐÁ½¸öÖ¡£¬µÚÒ»Ö¡ÊÇÓÃÀ´ÏÔʾӦÓÃÔØÈëµÄ½ø¶Èָʾ£¬Õâ¸öÖ¡ÊÇÇáÁ¿µÄ£¬ËùÒÔËü¼¸ºõÄÜÁ¢¼´ÏÂÔØºÍÔËÐС£µÚ¶þÖ¡±ãÊÇÓ¦Óñ¾Éí¡£
µ±Ò»¸öFlexÓ¦ÓõÄSystemManagerʵÀý½øÈëµ½µÚ¶þÖ¡£¬Ëü´´½¨Ò»¸öÖ÷Ó¦ÓõÄʵÀý¡£SystemManagerʵÀýÓÐÒ»¸öapplicationÊôÐÔ,ÔÚËüµÚ¶þÖ¡´´½¨Ó¦ÓöÔÏó֮ǰ£¬ËüÊÇnullµÄ¡£ÔÚÄǸöµã£¬Ó¦ÓÃʵÀý±»³õʼ»¯²¢ÔËÐÐËü×Ô¼ºµÄÆô¶¯´¦Àí¡£ÒâÖ¸ËùÓеÄÓ¦ÓöÔÏóÄÚ²¿µÄÉúÃüÖÜÆÚʼþ·¢Éú¡£ÄÚ²¿µÄÉúÃüÖÜÆÚʼþΪ£º
preinitializeÓ¦Óñ»³õʼ»¯£¬µ«ÈÔû´´½¨ÈκÎ×Ó×é¼þ¡£
initializeÓ¦ÓÃÒÑ´´½¨×Ó×é¼þ£¬µ«¼«²¼¾ÖÕâЩ×é¼þ¡£
creationCompleteÓ¦ÓÃÒѱ»³õʼʵÀý»¯Íê³É£¬²¢ÒѲ¼¾ÖËùÓеÄ×é¼þ¡£
Ò»µ©Ó¦ÓÃÍê³ÉËüµÄÄÚ²¿Æô¶¯´¦Àí£¬Ëüͨ¹ý·Ö·¢applicationCompleteʼþ֪ͨSystemManager¡£´ÓÕâ¸öµãÖ®ºó£¬Ó¦ÓÃ×¼±¸ÔËÐÐÁË¡£
SystemManagerÒ²¹ÜÀíËùÒÔ±»ÔÚǰ̨ÏÔʾµÄÄÚÈÝ£¬¼´ËùÓеÄpop ups£¬¹â±ê£¬¹¤¾ßÌáʾ¡£
SystmeManagerÓÐÒ»¸ötoplevelSystemManagerµÄÊôÐÔ£¬ÒýÓõ½µ±Ê±ÔÚFlashPlayerÀïÔËÐеĸù¼¶µÄSystemManagerʵÀý¡£µ±Ò»¸öÓ¦ÓÃÊÇ×÷ΪFlashPlayerµÄÖ÷Ó¦Óñ»ÔØÈëµÄ£¬Õâ¸öÊôÐÔ×ÜÊÇ×ÔÒýÓõģ¬È»¶ø£¬µ±Ò»¸öÓ¦ÓÃÊDZ»ÁíÒ»¸öÓ¦ÓÃÔØÈëµÄ£¬Õâ¸ö±»ÔØÈëÓ¦ÓõÄSystemManager¶ÔÏóµÄtopLevelSystemManagerÔòÊÇÒýÓõ½¸¸Ó¦Óá£
ËäÈ»Äã²»³£ÒªÒýÓÃSystemManager,µ«ÐèҪʱ¿ÉÒÔ×ö¡£ËùÓеÄUIComponents£¨°üÀ¨Application£©µÄ×ÓÀà¶¼ÓÐÒ»¸ösystemManagerÊôÐÔÒýÓõ½applicationµÄSystemManager¡£¿ª·¢Õß³£Ï²»¶Ê¹ÓÃSystemManagerÀ´¼àÌýÓ¦ÓÃÖÐÈκÎÏÔʾ¶ÔÏó·Ö·¢µÄʼþ¡£µ±Ê¼þðÅÝʱ£¬Óлú»á²Ù¿Ø(handle)ʼþµÄ×îºóµÄ¶ÔÏó±ãÊÇSystemManager.
FlashPlayerºÍ¿ò¼ÜµÄ²»Í¬
FlasyPlayerÊÇFlashºÍFlexÓ¦ÓõÄÔËÐл·¾³¡£ËüÄÜÔËÐÐ.swfÎļþ¡£¸ÃÎļþ°üº¬ÕâЩ×Ö½Ú´úÂ룺ÄÜÓëFlashPlayerͨÐÅ£¬ÃüÁîËüÖ´ÐÐÔØÈëͼÏñ£¬»Í¼£¬·¢ÆðhttpÇëÇóµÈµÈ²Ù×÷¡£FlashºÍFlexÓ¦ÓÃÖ»ÄÜ×öÄÇЩFlashPlayerÔÊÐíËûÃÇ×öµÄ£¬FlashPlayerÌṩ¿ÉÖ´ÐеÄAPI.
Ó¦ÓÃÖ»°üº¬ÃüÁ¶øFlashPlayerÔò¸ºÔðÔËÐÐÕâЩÃüÁËùÒÔFlashºÍFlexÓ¦ÓõIJ»Í¬²»ÊÇÄÚÈÝ£¬¶øÊÇÔõÑù´´½¨ÄÚÈÝ¡£
ʹÓÿò¼ÜµÄ´ú¼ÛÊÇ.swfÎļþ³ß´çµÄÔö³¤£¬ÕâÓëÓô¿ASдµÄÏîÄ¿Ðγɷ´²î¡£ÒòΪµ±Äã²»ÓÃFlex¿ò¼Ü£¬ÄãÊÇÖ±½ÓÒýÓÃFlashPlayerµÄÖ÷À࣬ÕâЩÀàÒѾÔÚFlashPlayerÖÐÁË£¬ËûÃDz»Ðè±»±àÒë½ø.swfÎļþ¡£ÔÚÓÃFlex¿ò¼Üʱ£¬¼òµ¥µÄÔö¼ÓÒ»¸ö×é¼þÒ²»áÔö¼ÓºÜ¶àµÄÎļþ³ß´ç£¬ÒòΪËüÐèÒª±àÒëµÄÒ»¸öÀà»òÒ»¸öÀà¿â²¢²»ÊÇFlashPlayerµÄÒ»²¿·Ö¡£
Framework Fundamentals¿ò¼Ü»ù´¡
Àí½âFlexÓ¦ÓóÌÐòµÄÉúÃüÖÜÆÚ
FlexÓ¦ÓõĸùÊÇSystemManger£¬ËüÊÇflash.display.MovieClipµÄ×ÓÀ࣬һ¸öFlash PlayerÏÔʾ¶ÔÏóÀàÐÍ¡£SystemManagerÓÐÁ½¸öÖ¡£¬µÚÒ»Ö¡ÊÇÓÃÀ´ÏÔʾӦÓÃÔØÈëµÄ½ø¶Èָʾ£¬Õâ¸öÖ¡ÊÇÇáÁ¿µÄ£¬ËùÒÔËü¼¸ºõÄÜÁ¢¼´ÏÂÔØºÍÔËÐС£µÚ¶þÖ¡±ãÊÇÓ¦Óñ¾Éí¡£
µ±Ò»¸öFlexÓ¦ÓõÄSystemManagerʵÀý½øÈëµ½µÚ¶þÖ¡£¬Ëü´´½¨Ò»¸öÖ÷Ó¦ÓõÄʵÀý¡£SystemManagerʵÀýÓÐÒ»¸öapplicationÊôÐÔ,ÔÚËüµÚ¶þÖ¡´´½¨Ó¦ÓöÔÏó֮ǰ£¬ËüÊÇnullµÄ¡£ÔÚÄǸöµã£¬Ó¦ÓÃʵÀý±»³õʼ»¯²¢ÔËÐÐËü×Ô¼ºµÄÆô¶¯´¦Àí¡£ÒâÖ¸ËùÓеÄÓ¦ÓöÔÏóÄÚ²¿µÄÉúÃüÖÜÆÚʼþ·¢Éú¡£ÄÚ²¿µÄÉúÃüÖÜÆÚʼþΪ£º
preinitializeÓ¦Óñ»³õʼ»¯£¬µ«ÈÔû´´½¨ÈκÎ×Ó×é¼þ¡£
initializeÓ¦ÓÃÒÑ´´½¨×Ó×é¼þ£¬µ«¼«²¼¾ÖÕâЩ×é¼þ¡£
creationCompleteÓ¦ÓÃÒѱ»³õʼʵÀý»¯Íê³É£¬²¢ÒѲ¼¾ÖËùÓеÄ×é¼þ¡£
Ò»µ©Ó¦ÓÃÍê³ÉËüµÄÄÚ²¿Æô¶¯´¦Àí£¬Ëüͨ¹ý·Ö·¢applicationCompleteʼþ֪ͨSystemManager¡£´ÓÕâ¸öµãÖ®ºó£¬Ó¦ÓÃ×¼±¸ÔËÐÐÁË¡£
SystemManagerÒ²¹ÜÀíËùÒÔ±»ÔÚǰ̨ÏÔʾµÄÄÚÈÝ£¬¼´ËùÓеÄpop ups£¬¹â±ê£¬¹¤¾ßÌáʾ¡£
SystmeManagerÓÐÒ»¸ötoplevelSystemManagerµÄÊôÐÔ£¬ÒýÓõ½µ±Ê±ÔÚFlashPlayerÀïÔËÐеĸù¼¶µÄSystemManagerʵÀý¡£µ±Ò»¸öÓ¦ÓÃÊÇ×÷ΪFlashPlayerµÄÖ÷Ó¦Óñ»ÔØÈëµÄ£¬Õâ¸öÊôÐÔ×ÜÊÇ×ÔÒýÓõģ¬È»¶ø£¬µ±Ò»¸öÓ¦ÓÃÊDZ»ÁíÒ»¸öÓ¦ÓÃÔØÈëµÄ£¬Õâ¸ö±»ÔØÈëÓ¦ÓõÄSystemManager¶ÔÏóµÄtopLevelSystemManagerÔòÊÇÒýÓõ½¸¸Ó¦Óá£
ËäÈ»Äã²»³£ÒªÒýÓÃSystemManager,µ«ÐèҪʱ¿ÉÒÔ×ö¡£ËùÓеÄUIComponents£¨°üÀ¨Application£©µÄ×ÓÀà¶¼ÓÐÒ»¸ösystemManagerÊôÐÔÒýÓõ½applicationµÄSystemManager¡£¿ª·¢Õß³£Ï²»¶Ê¹ÓÃSystemManagerÀ´¼àÌýÓ¦ÓÃÖÐÈκÎÏÔʾ¶ÔÏó·Ö·¢µÄʼþ¡£µ±Ê¼þðÅÝʱ£¬Óлú»á²Ù¿Ø(handle)ʼþµÄ×îºóµÄ¶ÔÏó±ãÊÇSystemManager.
FlashPlayerºÍ¿ò¼ÜµÄ²»Í¬
FlasyPlayerÊÇFlashºÍFlexÓ¦ÓõÄÔËÐл·¾³¡£ËüÄÜÔËÐÐ.swfÎļþ¡£¸ÃÎļþ°üº¬ÕâЩ×Ö½Ú´úÂ룺ÄÜÓëFlashPlayerͨÐÅ£¬ÃüÁîËüÖ´ÐÐÔØÈëͼÏñ£¬»Í¼£¬·¢ÆðhttpÇëÇóµÈµÈ²Ù×÷¡£FlashºÍFlexÓ¦ÓÃÖ»ÄÜ×öÄÇЩFlashPlayerÔÊÐíËûÃÇ×öµÄ£¬FlashPlayerÌṩ¿ÉÖ´ÐеÄAPI.
Ó¦ÓÃÖ»°üº¬ÃüÁ¶øFlashPlayerÔò¸ºÔðÔËÐÐÕâЩÃüÁËùÒÔFlashºÍFlexÓ¦ÓõIJ»Í¬²»ÊÇÄÚÈÝ£¬¶øÊÇÔõÑù´´½¨ÄÚÈÝ¡£
ʹÓÿò¼ÜµÄ´ú¼ÛÊÇ.swfÎļþ³ß´çµÄÔö³¤£¬ÕâÓëÓô¿ASдµÄÏîÄ¿Ðγɷ´²î¡£ÒòΪµ±Äã²»ÓÃFlex¿ò¼Ü£¬ÄãÊÇÖ±½ÓÒýÓÃFlashPlayerµÄÖ÷À࣬ÕâЩÀàÒѾÔÚFlashPlayerÖÐÁË£¬ËûÃDz»Ðè±»±àÒë½ø.swfÎļþ¡£ÔÚÓÃFlex¿ò¼Üʱ£¬¼òµ¥µÄÔö¼ÓÒ»¸ö×é¼þÒ²»áÔö¼ÓºÜ¶àµÄÎļþ³ß´ç£¬ÒòΪËüÐèÒª±àÒëµÄÒ»¸öÀà»òÒ»¸öÀà¿â²¢²»ÊÇFlashPlayerµÄÒ»²¿·Ö¡£
ÈôÀàµÄ°üÊÇÒÔflash.¿ªÍ·£¬ËüÊÇFlashPlayerµÄÒ»²¿·Ö£»
ÈôÀàµÄ°üÊÇÒÔmx.¿ª¹Ø£¬ËüÊÇFlex¿ò¼ÜµÄÒ»²¿·Ö£»
MXML±êÇ©¼¸ºõ×ÜÊÇ(ÉÙÊýµÄÀýÍâ)¶ÔÓ¦Flex¿ò¼ÜÀà¡£
ÈôÀàµÄ°üÊÇÒÔmx.¿ª¹Ø£¬ËüÊÇFlex¿ò¼ÜµÄÒ»²¿·Ö£»
MXML±êÇ©¼¸ºõ×ÜÊÇ(ÉÙÊýµÄÀýÍâ)¶ÔÓ¦Flex¿ò¼ÜÀà¡£
Bootstarapping Flex Applications
Ò»¸öFlexÓ¦Óõĸù²¢²»ÊÇÒ»¸öApplication¶ÔÏó£¬Êµ¼ÊÉÏÒ»¸öApplication±êÇ©´´½¨µÄÊÇÒ»¸ömx.managers.SystemManager¶ÔÏó¡£
flash.display.MovieClipÊÇÒ»¸öÏÔʾ¶ÔÏó£¬ÔÊÐíÄã¶Ôʱ¼äÖá±à³Ì¡£µ«ÔÚFlexÓ¦ÓÃÖв¢²»ÔõÓÃʱ¼äÖᣬÒòΪûÓбà³Ì·½·¨Ôö¼ÓÒ»¸öÖ¡µ½µ½¸öʱ¼äÖá¡£µ«Ê±¼äÖáºÍÖ¡ÈÔÊÇSystmeManagerµÄ»ù±¾²¿·ÖÖ®Ò»¡£
ÒòΪûÓз½·¨±à³ÌµÄÔö¼ÓÖ¡£¬¼¸ºõFlexÓ¦ÓÃÖеÄËùÓÐÏÔʾ¶ÔÏóÖ»ÓÉÒ»¸öÖ¡×é³É£¬µ«SystemManagerÊǸöÀýÍ⣬ËüÓÐÁ½¸öÖ¡£¬Ò»¸öÓÃÓÚÔ¤×°ÔØ£¬Ö÷Ó¦ÓöÔÏó´æÔÚµÚ¶þÖ¡ÖС£Ò»°ãÇé¿öÏ£¬Äã²»ÐèÖªµÀÕâЩ£¬µ«ÔÚÖÁÉÙÁ½¸öÇé¿öÏÂÄãÐèÁ˽âËü£ºÔÚÒ»¸öFlexÓ¦ÓÃÖÐÔØÈëÁíÒ»¸öFlexÓ¦Óã»¶¨ÖÆÔ¤×°ÔØÆ÷¡£
Loading One Flex Application into Another Flex Application
µ±Ò»¸öSWFLoaderÔØÈëÒ»¸öFlex Ó¦Óã¬Õâ¸öSWFLoader¶ÔÏóµÄconternÊôÐÔÌṩÁ˶Ա»ÔØÈëÓ¦ÓõĸùµÄÒýÓã¬Ò²¼´ÊDZ»ÔØÈëÓ¦ÓõÄSystemManager¶ÔÏó¡£Õâ¸öSystemManagrÀඨÒåÒ»¸öapplicationÊôÐÔ¿ÉÒýÓÃApplication¶ÔÏó¡£µ«Õâ¸öÊôÐÔÔÚFlex Ó¦Óñ»ÔØÈëʱ»¹ÊÇnull,ÔÚµÚ¶þ֮֡ǰ£¬ËüÊDz»»á±»´´½¨µÄ¡£ÄÇÒªÔõÑùÒýÓÃËüÄØ£¿ÓиöÓÅÑŵķ½·¨¿ÉÒÔ½â¾öÕâ¸öÎÊÌ⣺
µ±Ò»¸öSWFLoaderÔØÈëºÍ³õʼ»¯ÁËÄÚÈÝ£¬Ëü·Ö·¢initʼþ£¬ÔÚinitµÄʼþ´¦ÀíÀÄãÄܹ»ÒýÓñ»ÔØÈëÄÚÈݵÄSystemManagerÁË£¬´ËʱÄã¾ÍÔö¼ÓÒ»¸öʼþÕìÌýÆ÷£¬¼àÌýÕâ¸öSystemManagerµÄapplicationCompleteʼþ¡£¶øÔÚÕâ¸öapplicationCompleteµÄʼþ´¥·¢Ö®ºó£¬ÔÚËüµÄ´¦ÀíÀÄã¾Í¿ÉÒÔÒýÓñ»½øÈëÄÚÈݵÄApplication¶ÔÏóÁË¡£
Àý×Ó£º
Òª±»ÔØÈëµÄÓ¦ÓãºB.MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
µ±Ò»¸öSWFLoaderÔØÈëºÍ³õʼ»¯ÁËÄÚÈÝ£¬Ëü·Ö·¢initʼþ£¬ÔÚinitµÄʼþ´¦ÀíÀÄãÄܹ»ÒýÓñ»ÔØÈëÄÚÈݵÄSystemManagerÁË£¬´ËʱÄã¾ÍÔö¼ÓÒ»¸öʼþÕìÌýÆ÷£¬¼àÌýÕâ¸öSystemManagerµÄapplicationCompleteʼþ¡£¶øÔÚÕâ¸öapplicationCompleteµÄʼþ´¥·¢Ö®ºó£¬ÔÚËüµÄ´¦ÀíÀÄã¾Í¿ÉÒÔÒýÓñ»½øÈëÄÚÈݵÄApplication¶ÔÏóÁË¡£
Àý×Ó£º
Òª±»ÔØÈëµÄÓ¦ÓãºB.MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function setBackground(color:Number):void {
canvas.setStyle("backgroundColor", color);
}
canvas.setStyle("backgroundColor", color);
}
]]>
</mx:Script>
<mx:Canvas id="canvas" backgroundColor="#FFFFFF" width="100" height="100" />
</mx:Application>
¸¸Ó¦Óãº
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.managers.SystemManager;
import mx.events.FlexEvent;
</mx:Script>
<mx:Canvas id="canvas" backgroundColor="#FFFFFF" width="100" height="100" />
</mx:Application>
¸¸Ó¦Óãº
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.managers.SystemManager;
import mx.events.FlexEvent;
private function initHandler(event:Event):void {
event.target.content.addEventListener(FlexEvent.APPLICATION_COMPLETE,
applicationCompleteHandler);
}
event.target.content.addEventListener(FlexEvent.APPLICATION_COMPLETE,
applicationCompleteHandler);
}
private function applicationCompleteHandler(event:Event):void {
event.target.application.setBackground(0xFFFF00);
}
event.target.application.setBackground(0xFFFF00);
}
]]>
</mx:Script>
<mx:SWFLoader source="B.swf" init="initHandler(event)" />
</mx:Application>
</mx:Script>
<mx:SWFLoader source="B.swf" init="initHandler(event)" />
</mx:Application>
Ìáʾ£º
Flex 2.0.1ÄÚ½¨µÄÌØÐÔ´´½¨Ò»¸öÄ£¿éÓ¦Óã¬ÔÚÔËÐÐʱ½«¼¸¸ö.swfÎļþ·ì×°ÔÚÒ»Æð¡£ÔÚÐí¶àÇé¿öÏ£¬Ê¹ÓÃÄ£¿éÊǸü¼òµ¥µÄ·½·¨¡£
Understanding Application Domains
Ò»¸öÓ¦ÓÃÓòÊÇÔËÐÐÔÚFlashPlayerÖеķָôµÄÒ»¸öÓ¦ÓÃ?????????¡£ÔÚ¶àÊýÇé¿öÏ£¬Ö»ÓÐÒ»¸öÓ¦ÓÃÔËÐÐÔÚFlashPlayerÖУ¬ÕâʱֻÓÐÒ»¸öÓ¦ÓÃÓò¡£µ«µ±ÄãÔÚÒ»¸öÒÑ´æÔÚµÄÓ¦ÓÃÖÐÔØÈ븽¼ÓµÄ.swfÎļþʱ£¬Äã¿ÉÄÜÐèҪΪ¸½¼ÓµÄÓ¦Óô´½¨ÐµÄÓ¦ÓÃÓò¡£
Flex 2.0.1ÄÚ½¨µÄÌØÐÔ´´½¨Ò»¸öÄ£¿éÓ¦Óã¬ÔÚÔËÐÐʱ½«¼¸¸ö.swfÎļþ·ì×°ÔÚÒ»Æð¡£ÔÚÐí¶àÇé¿öÏ£¬Ê¹ÓÃÄ£¿éÊǸü¼òµ¥µÄ·½·¨¡£
Understanding Application Domains
Ò»¸öÓ¦ÓÃÓòÊÇÔËÐÐÔÚFlashPlayerÖеķָôµÄÒ»¸öÓ¦ÓÃ?????????¡£ÔÚ¶àÊýÇé¿öÏ£¬Ö»ÓÐÒ»¸öÓ¦ÓÃÔËÐÐÔÚFlashPlayerÖУ¬ÕâʱֻÓÐÒ»¸öÓ¦ÓÃÓò¡£µ«µ±ÄãÔÚÒ»¸öÒÑ´æÔÚµÄÓ¦ÓÃÖÐÔØÈ븽¼ÓµÄ.swfÎļþʱ£¬Äã¿ÉÄÜÐèҪΪ¸½¼ÓµÄÓ¦Óô´½¨ÐµÄÓ¦ÓÃÓò¡£
All Flex and Flash applications are composed of collections of classes. An applica-
tion domain holds the collections of classes for an application or applications. When
just one application is running in Flash Player, the concept of an application domain
is practically a formality because you are guaranteed that an .swf will never contain
more than one definition for a class. However, when you load an additional .swf file,
there is a possibility that it will contain a definition for a class by the same name as
one that is already loaded from another .swf file. An application domain ensures that
within the domain there is only one definition for each class. Therefore, it has a set of
rules for determining how to choose between conflicting definitions if such a sce-
nario presents itself.
tion domain holds the collections of classes for an application or applications. When
just one application is running in Flash Player, the concept of an application domain
is practically a formality because you are guaranteed that an .swf will never contain
more than one definition for a class. However, when you load an additional .swf file,
there is a possibility that it will contain a definition for a class by the same name as
one that is already loaded from another .swf file. An application domain ensures that
within the domain there is only one definition for each class. Therefore, it has a set of
rules for determining how to choose between conflicting definitions if such a sce-
nario presents itself.
If an application is loaded into an application domain with a parent, it essentially
inherits all the class definitions from the parent application domain. The result is
that the child application domain cannot have class definitions for classes that are
otherwise defined in the parent application domain. For example, if you load one
Flex application .swf into another Flex application .swf with the default settings,
there would be two application domains but one would be a child of the other, and
all duplicate Flex framework classes from the child would be disregarded in favor of
the same classes from the parent application domain. This is often appropriate, and
it has several possible benefits:
inherits all the class definitions from the parent application domain. The result is
that the child application domain cannot have class definitions for classes that are
otherwise defined in the parent application domain. For example, if you load one
Flex application .swf into another Flex application .swf with the default settings,
there would be two application domains but one would be a child of the other, and
all duplicate Flex framework classes from the child would be disregarded in favor of
the same classes from the parent application domain. This is often appropriate, and
it has several possible benefits:
* It uses less memory. If the duplicate classes were not disregarded, memory usage
would increase.
would increase.
* Singleton manager classes are accessible to both the parent and the child applica-
tions (meaning that just one instance of the class is shared by parent and child
applications).
tions (meaning that just one instance of the class is shared by parent and child
applications).
* Theoretically, it is possible to compile the child .swf files by excluding any dupli-
cate classes the child .swf would inherit at runtime from the parent application
domain. This would reduce the file size overhead in child .swf files.
cate classes the child .swf would inherit at runtime from the parent application
domain. This would reduce the file size overhead in child .swf files.
Just as there are cases in which this default child domain behavior is useful, some-
times it works at cross purposes with the needs or requirements of a project. For
example, consider the scenario in which two applications are built using two classes
with the same name but very different implementations. If one is loaded into the
other, the child will not work as intended because that class will be discarded in the
child, and the parent version will be used in both applications. In such a case, it is
clear that there is a need to be able to completely partition the applications into sepa-
rate application domains. Separate application domains ensure that the sorts of con-
flicts just described don¡¯t occur. However, it is important to use these sorts of
exclusive application domains only when necessary because they will increase mem-
ory usage.
times it works at cross purposes with the needs or requirements of a project. For
example, consider the scenario in which two applications are built using two classes
with the same name but very different implementations. If one is loaded into the
other, the child will not work as intended because that class will be discarded in the
child, and the parent version will be used in both applications. In such a case, it is
clear that there is a need to be able to completely partition the applications into sepa-
rate application domains. Separate application domains ensure that the sorts of con-
flicts just described don¡¯t occur. However, it is important to use these sorts of
exclusive application domains only when necessary because they will increase mem-
ory usage.
µÚ1ÖÖ£º±»ÔØÈëµÄ.swfÎļþÔËÐÐÔÚÒ»¸öеÄÓ¦ÓÃÓò£¬×÷ΪÒÑ´æÔÚÓ¦ÓÃÓòµÄchild¡£
µÚ2ÖÖ£º±»ÔØÈëµÄ.swfÎļþÔËÐÐÔÚÒ»¸öеÄÓ¦ÓÃÓò
µÚ3ÖÖ£ºÒ»¸ö.swfÎļþ±»ÔØÈëµ½ÏàͬӦÓÃÓò¡£ÓÃÓÚÔËÐÐʱ¹²Ïí¿â£¬µ±ÄãÏëÔËÐÐÊ±ÔØÈë×ÖÌåºÍÆäËüµÄassets¿âÔÚÖ÷Ó¦ÓÃÀïʹÓÃʱ£¬ËüÒ²ÊÇÓÐÓõġ£
µÚ3ÖÖ£ºÒ»¸ö.swfÎļþ±»ÔØÈëµ½ÏàͬӦÓÃÓò¡£ÓÃÓÚÔËÐÐʱ¹²Ïí¿â£¬µ±ÄãÏëÔËÐÐÊ±ÔØÈë×ÖÌåºÍÆäËüµÄassets¿âÔÚÖ÷Ó¦ÓÃÀïʹÓÃʱ£¬ËüÒ²ÊÇÓÐÓõġ£
Àý×Ó£º
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); ½«µ±Ç°Ó¦ÓÃÓò×÷ΪÐÂÓ¦ÓÃÓòµÄ¸¸Ó¦ÓÃÓò
// context.applicationDomain = new ApplicationDomain();н¨Ò»¸ö·ÖÀëµÄ¶ÀÁ¢µÄÓ¦ÓÃÓò
//// context.applicationDomain = ApplicationDomain.currentDomain; ʹÓõ±Ç°µÄÓ¦ÓÃÓò
var request:URLRequest = new URLRequest("RuntimeLoadingExample.swf");
var loader:Loader = new Loader();
loader.load(request, context);
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); ½«µ±Ç°Ó¦ÓÃÓò×÷ΪÐÂÓ¦ÓÃÓòµÄ¸¸Ó¦ÓÃÓò
// context.applicationDomain = new ApplicationDomain();н¨Ò»¸ö·ÖÀëµÄ¶ÀÁ¢µÄÓ¦ÓÃÓò
//// context.applicationDomain = ApplicationDomain.currentDomain; ʹÓõ±Ç°µÄÓ¦ÓÃÓò
var request:URLRequest = new URLRequest("RuntimeLoadingExample.swf");
var loader:Loader = new Loader();
loader.load(request, context);
Àí½âÔ¤¼ÓÔØÆ÷Understanding the Preloader
ĬÈϵģ¬ËùÓеÄFlex applications¶¼ÓÐÒ»¸öÔ¤¼ÓÔØÆ÷£¬Í¨¹ýÒ»¸ö½ø¶ÈÌõָʾӦÓüÓÔØºÍ³õʼ»¯µÄ½ø¶È¡£Í¨³£µÄ£¬½ø¶ÈÌõ×¢²áÒ»¸ö»ò¶à¸öµÄÕìÌýÆ÷£¬Îªpreloader¶ÔÏó·Ö·¢µÄһϵÁÐʼþ£¬ÒÔÏÂÊÇpreloaderµÄÓÐЧʼþ£º
progressָʾÏÂÔØ½ø¶È
completeָʾÏÂÔØÍê³É
rslErrorָʾÔËÐÐʱ¹²Ïí¿â²»Äܱ»ÔØÈë
rslProgressָʾÔËÐÐʱ¹²Ïí¿âµÄÏÂÔØ½ø¶È
rslCompleteָʾÔËÐÐʱ¹²Ïí¿âµÄÏÂÔØÍê³É
initProgressָʾӦÓÃÕýÔÚ³õʼ»¯
initCompleteָʾӦÓÃÒѾ³õʼ»¯
Ò»µ©,system manager½øÈëµ½µÚ¶þÖ¡£¬Ó¦ÓýøÐÐ×ÔÉíµÄ´´½¨ºÍ³õʼ»¯¡£.....
ĬÈϵģ¬ËùÓеÄFlex applications¶¼ÓÐÒ»¸öÔ¤¼ÓÔØÆ÷£¬Í¨¹ýÒ»¸ö½ø¶ÈÌõָʾӦÓüÓÔØºÍ³õʼ»¯µÄ½ø¶È¡£Í¨³£µÄ£¬½ø¶ÈÌõ×¢²áÒ»¸ö»ò¶à¸öµÄÕìÌýÆ÷£¬Îªpreloader¶ÔÏó·Ö·¢µÄһϵÁÐʼþ£¬ÒÔÏÂÊÇpreloaderµÄÓÐЧʼþ£º
progressָʾÏÂÔØ½ø¶È
completeָʾÏÂÔØÍê³É
rslErrorָʾÔËÐÐʱ¹²Ïí¿â²»Äܱ»ÔØÈë
rslProgressָʾÔËÐÐʱ¹²Ïí¿âµÄÏÂÔØ½ø¶È
rslCompleteָʾÔËÐÐʱ¹²Ïí¿âµÄÏÂÔØÍê³É
initProgressָʾӦÓÃÕýÔÚ³õʼ»¯
initCompleteָʾӦÓÃÒѾ³õʼ»¯
Ò»µ©,system manager½øÈëµ½µÚ¶þÖ¡£¬Ó¦ÓýøÐÐ×ÔÉíµÄ´´½¨ºÍ³õʼ»¯¡£.....
