flashÓëjavascriptµÄ½»»¥
flashÓëjavascriptµÄ½»»¥¿ÉÄÜÌÖÂ۵ıȽ϶à,½ñÌìΪ´ó¼Ò½éÉÜÏÂÈçºÎʹÓÃflexÓëjavascript½øÐн»»¥
Ò»¡¢ÔÚJavaScriptÖе÷ÓÃFlex·½·¨
ÔÚFlexÖпÉÒÔÓÃExternalInterfaceÀ´µ÷ÓÃFlexµÄ·½·¨£¬Í¾¾¶ÊÇ
1.ͨ¹ýÔÚFlexÓ¦Óÿɵ÷Ó÷½·¨ÁбíÖÐÌí¼ÓÖ¸¶¨µÄ¹«Ó÷½·¨¡£ÔÚFlexÓ¦ÓÃÖÐͨ¹ýµ÷ÓÃaddCallback()¿ÉÒÔ°ÑÒ»¸ö·½·¨Ìí¼Óµ½´ËÁбíÖС£addCallback½«Ò»¸öActionScriptµÄ·½·¨×¢²áΪһ¸öJavaScriptºÍVBScript¿ÉÒÔµ÷Óõķ½·¨¡£
addCallback()º¯ÊýµÄ¶¨ÒåÈçÏ£º
addCallback(function_name:String, closure:Function):void
function_name²ÎÊý¾ÍÊÇÔÚHtmlÒ³ÃæÖнű¾µ÷Óõķ½·¨Ãû¡£closure²ÎÊýÊÇÒªµ÷Óõı¾µØ·½·¨£¬Õâ¸ö²ÎÊý¿ÉÒÔÊÇÒ»¸ö·½·¨Ò²¿ÉÒÔÊǶÔÏóʵÀý¡£
¾Ù¸öÀý×Ó£º
<mx:Script>
import flash.external.*;
public function myFunc():Number {
return 42;
}
public function initApp():void {
ExternalInterface.addCallback("myFlexFunction",myFunc);
}
</mx:Script>
2.ÄÇôÔÚHtmlÒ³ÃæÖУ¬ÏÈ»ñµÃSWF¶ÔÏóµÄÒýÓã¬Ò²¾ÍÊÇÓÃ<object .../>ÉùÃ÷µÄSwfµÄIdÊôÐÔ£¬±ÈÈç˵ÊÇMyFlexApp¡£È»ºó¾Í¿ÉÒÔÓÃÒÔÏ·½Ê½µ÷ÓÃFlexÖеķ½·¨¡£
<SCRIPT language='JavaScript' charset='utf-8'>
function callApp() {
var x = MyFlexApp.myFlexFunction();
alert(x);
}
</SCRIPT>
<button onclick="callApp()">Call App</button>
¶þ¡¢ÔÚFlexÖе÷Óà JavaScript
Äã¿ÉÒÔµ÷ÓÃHtmlÒ³ÃæÖеÄJavaScript£¬Í¨¹ýÓëJavaScriptµÄ½»»¥£¬¿ÉÒԸıäStyle£¬µ÷ÓÃÔ¶³Ì·½·¨¡£»¹¿ÉÒÔ½«Êý¾Ý´«µÝ¸øHtmlÒ³Ã棬´¦ÀíºóÔÙ·µ»Ø¸øFlex£¬Íê³ÉÕâÑùµÄ¹¦ÄÜÖ÷ÒªÓÐÁ½ÖÖ·½·¨£ºExternalInterface()ºÍnavigateToUrl()¡£
ÔÚFlexÖе÷ÓÃJavaScript×î¼òµ¥µÄ·½·¨ÊÇʹÓÃExternalInterface()£¬¿ÉÒÔʹÓôËAPIµ÷ÓÃÈÎÒâJavaScript£¬´«µÝ²ÎÊý£¬»ñµÃ·µ»ØÖµ£¬Èç¹ûµ÷ÓÃʧ°Ü£¬FlexÅ׳öÒ»¸öÒì³£¡£
ExternalInterface·â×°Á˶Ôä¯ÀÀÆ÷Ö§³ÖµÄ¼ì²é£¬¿ÉÒÔÓÃavailableÊôÐÔÀ´²é¿´¡£
ExternalInterfaceµÄʹÓ÷dz£¼òµ¥£¬Óï·¨ÈçÏ£º
flash.external.ExternalInterface.call(function_name: String[, arg1, ...]):Object;
²ÎÊý
Ïà¹ØÎĵµ£º
¹¤³§Ä£Ê½·ÖΪ¼òµ¥¹¤³§Ä£Ê½ºÍ¸´ÔÓ¹¤³§Ä£Ê½£¬Ç°ÕßÊÇʹÓÃÒ»¸öÀàÀ´Éú³ÉʵÀý£¬Í¨³£ÊÇÒ»¸öµ¥Ì壬ºóÕßÊÇʹÓÃ×ÓÀàÀ´¾ö¶¨Ò»¸ö³ÉÔ±±äÁ¿ÊÇÄĸöÀàµÄ¾ßÌåʵÀý£¬Ò²¾ÍÊǼòµ¥¹¤³§°üº¬ÔÚ¸´ÔÓ¹¤³§Ö®ÖС£
ÏÂÃæͨ¹ýÒ»¸ö¾ßÌåµÄʵÀýÀ´¾ßÌåµÄ˵˵Õ⹤³§µÄÒ»¶þ°É¡£
ÓÃAjax¼¼Êõ·¢ÆðÒì²½ÇëÇóÊÇÏÖÔÚweb¿ª·¢ÖеÄÒ»¸ö³£¼ûÈÎÎñ¡£
1 // ......
µÚ9Õ ´úÂë·ç¸ñ
¼ÆËã»ú³ÌÐòÊÇÈËÀàÖÆÔì³öÀ´µÄ×ÔÓµÄÊÂÎï¡£³ÌÐòͨ³£Óɺܶಿ·Ö×é³É£¬±íÏÖΪº¯Êý¡¢Óï¾äºÍ±í´ïʽ£¬ËüÃDZØÐë׼ȷÎÞÎóµØ°´ÕÕ˳ÐòÅÅÁС£×îÖյĽá¹û¼¸ºõ¶¼ºÍʵÏÖËüµÄ³ÌÐòûÓÐʲôÏàËÆÖ®´¦¡£ÔÚÈí¼þµÄ²úÆ·ÉúÃüÖÜÆÚÖУ¬Í¨³£ËüÃǶ¼»á±»Ð޸ġ£°ÑÒ»¸öÕýÈ·µÄ³ÌÐòת»¯ÎªÁíÒ»¸öͬÑùÕýÈ·µ«·ç¸ñ²»Í¬µÄ³ÌÐò£¬ÊÇÒ»¸ö¼«¾ß ......
JavaScript¾ÍÕâô»ØÊ£º»ù´¡ÖªÊ¶
1 ´´½¨½Å±¾¿é
1: <script language="JavaScript">
2: JavaScript code goes here
3: </script>
¡¡
2 Òþ²Ø½Å±¾´úÂë
1: <script language="JavaScript">
2: <!--
3: document.write("Hello");
4: // -->
5: </script>
ÔÚ²»Ö§³ÖJavaScriptµÄä¯ÀÀ ......
ÓïÑÔ²ã´Î·½Ãæ
¡¡¡¡Ñ»·
¡¡¡¡Ñ»·ÊǺܳ£ÓõÄÒ»¸ö¿ØÖƽṹ£¬´ó²¿·Ö¶«Î÷ÒªÒÀ¿¿ËüÀ´Íê³É£¬ÔÚJavaScriptÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃfor(;;),while(),for(in)ÈýÖÖÑ»·£¬ÊÂʵÉÏ£¬ÕâÈýÖÖÑ»·ÖÐfor(in)µÄЧÂʼ«²î£¬ÒòΪËûÐèÒª²éѯɢÁмü£¬Ö»Òª¿ÉÒÔ¾ÍÓ¦¸Ã¾¡Á¿ÉÙÓá£for(;;)ºÍwhileÑ»·µÄÐÔÄÜÓ¦¸Ã˵»ù±¾(ƽʱʹÓÃʱ)µÈ¼Û¡£
¡¡¡¡¶øÊÂʵÉÏ£¬ÈçºÎ ......
DOM
Document Object Model
ÊDZí´ïʽXMLÎĵµµÄ³£¼û·½Ê½£¬DOM¸ø¿ª·¢ÕßÌṩÁËÒ»ÖÖ¶¨Î»XML²ã¼¶½á¹¹µÄÖ±¹Û·½·¨¡£
½âÎö²¢ä¯ÀÀDOMÎĵµµÄÓÐЧ·½·¨ÎÞÒÉÄܼò»¯JavaScriptµÄ¿ª·¢¡£
¹é¸ù½áµ×£¬JavaScriptÖоø´ó²Ù×÷¶¼ÊÇJavaScriptºÍÍøÒ³ÀﲻͬµÄHTMLÔªËØÖ®¼äµÄ½»»¥£¬¶øDOMÔòÊǼò»¯ÕâÒ»¹ý³ÌµÄ³öÉ«¹¤¾ß¡£
ÀýÈ磺
» ......