Flex3ÓëÒ³ÃæJavaScriptµÄÏ໥µ÷ÓÃ
ÈÕÇ°×öÏîÄ¿£¬ÐèÒª°ÑÒ³ÃæµÄJS´úÂë³é³öÀ´·Åµ½Ò»¸ö.jsÎļþÖУ¬ÓÉÓÚflex³ÌÐòÊÇÒÔdiv+SWFObjectµÄ·½Ê½Ç¶Èëµ½Ò³ÃæµÄ£¬ÎªÁ˴ﵽĿ±êÍøÕ¾Ö»ÐèÒªÒýÓÃÒ»¸ö.jsÎļþ¼´ÊµÏÖÒýÓÃÏîÄ¿¹¤³ÌµÄÄ¿µÄ£¬ËùÒÔÒ²Òª°ÑSWFObjectµÄ´úÂë·Åµ½.jsÎļþÖС£
˼·ÊÇÓÃdocument.write()°ÑÒýÓÃswfÎļþµÄ´úÂëд½øÒ³Ã棬Ȼºó°ÑflexÒªµ÷ÓõÄjsº¯Êý¶¼·Åµ½.jsÎļþÖÐ
ºÜ¿ì£¬¾ÍǨÒÆÍê±ÏÁË¡£²âÊÔing...
Ïë²»µ½µÄÊÇ£¬flexÖÐÓÃExternalInterface.call("methodName",params);µ÷JSº¯ÊýȱûÓзµ»ØÖµ£¬ÓÃalert("a")µ¯³öһϣ¬¹ûȻûÓе÷Óõ½¡£ÕâÊÇΪʲôÄØ£¿ÄѵÀ°ÑSWFÓÃdocument.writeµÄ·½Ê½¼ÓÈëµ½Ò³ÃæºóȨÏÞ½µµÍÁË£¿
·Å¹·ÕÒÁËһϣ¬Ëƺõ´ó¼ÒµÄµ÷Óö¼ºÜÕý³£……°¦……ÈËÉú×îÍ´¿àµÄÊÂÇéĪ¹ýÓÚ´ËÁË¡£
ͻȻÏëµ½infoqµÄһЩÁ¬½ÓÏÔʾµÄÊÇÀàËÆjavascript:void(0)µÄ×ÖÑù£¬ÓÚÊǺõ£¬ÎÒÏëµ½ÁËÓÃflexµÄURLRequestµ÷ÓÃÒ³ÃæµÄJS¡£
Á¢¿Ì³¢ÊÔ
flexÖУº
var req:URLRequest = new URLRequest("javascript:test('hello')");
navigateToURL(req,"_self");
ÔÚJSÖУº
function test(str){
alert("ÄãºÃ" + str);
return "world";
}
ä¯ÀÀÆ÷µ¯³ö¶Ô»°¿ò£¬ÀïÃæµÄÎÄ×ÖÏÔʾҲÕý³£¡£
Õâ˵Ã÷ÓÃURLRequestµ÷ÓÃÊÇûÎÊÌâµÄ¡£
µ«ÊÇ……ä¯ÀÀÆ÷È´ÌøתÁË£¬Ò³ÃæÏÔʾworld¡£
ºÜÃ÷ÏÔ£¬²»¿ÉÒÔµ¥´¿µØÕâôµ÷¡£
Ôõô°ìÄØ£¿·ÁËÒ»ÏÂflexµÄÎĵµ£¬ÔÀ´ExternalInterfaceÓиöaddCallBackµÄ·½·¨£¬Ê¹ÓÃËü¿ÉÒÔ½¨Ò»¸öJSµÄ»Øµ÷º¯Êý
ʹÓ÷½·¨ÈçÏ£º
ExternalInterface.addCallBack("returnValue",returnValue);//µÚÒ»¸ö²ÎÊýÊÇ¿ª·Å¸øJSµÄº¯ÊýÃû£¬µÚ¶þ¸ö²ÎÊýÊǶÔÓ¦µÄAS·½·¨¡£
flexÖУº
public function invokeJavaScript(details:String):void{
var JavaScriptRequest:URLRequest = new URLRequest("javascript:" + details);
navigateToURL(JavaScriptRequest,"_self");
}
public function returnValue(value:String):void{
this.value = value;
}
private function testASJS():void{
invokeJavaScript("test('seal','ÀϺú')");
}
jsÖУº
function thisMovie(flexName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[flexName];
} else {
return document[flexName];
}
}
function sendToActionScript(flexName,value) {
thisMovie(flexName).returnValue(value);
}
function test(flexName,param1){
sendToAction
Ïà¹ØÎĵµ£º
1.document.formName.item('itemname')µÄÎÊÌâ
˵Ã÷£ºIEÏ¿ÉÒÔʹÓÃdocument.formName.item('itemname')ºÍdocument.formName.elements('elementsName');
FFÏÂÖ»ÄÜʹÓÃdocuement.formName.elements('elementsName');
½â¾ö·½·¨£ºÍ³Ò»Ê¹ÓÃdocuement.formName.elements('elementsName');
2.¼¯ºÏÀà¶ÔÏóÎÊÌâ
˵Ã÷£ºIEÏ¿ÉÒÔʹÓÃ[]ºÍ ......
×î½üÔÚ¿´Flex3ȨÍþÖ¸ÄÏ£¬ÀïÃæ¶ÔÒ³Ãæ¼Ü¹¹ºÍRIA¼¼Êõ×ܽáµÄºÜºÃ¡£
Ò». »ùÓÚÒ³Ãæ¼Ü¹¹µÄWebÓ¦ÓÃÁ÷³Ì
1. Óû§´ò¿ªä¯ÀÀÆ÷£¬ÏòWEB·þÎñÆ÷ÇëÇóÒ»¸öÒ³Ãæ¡£
2. WEB·þÎñÆ÷ÊÕµ½ÇëÇó¡£
3. (optional)ÍøÂç·þÎñÆ÷°ÑÇëÇ󽻸øÓ¦Ó÷þÎñÆ÷À´¶¯Ì¬×é×°Ò³Ãæ¡£
&nb ......
JavaScript ÄÜ×öʲô£¿
JavaScript Ϊ HTML Éè¼ÆʦÌṩÁËÒ»ÖÖ±à³Ì¹¤¾ß HTML ´´×÷ÕßÍùÍù¶¼²»ÊdzÌÐòÔ±£¬µ«ÊÇ JavaScript È´ÊÇÒ»ÖÖÖ»ÓµÓм«Æä¼òµ¥µÄÓï·¨µÄ½Å±¾ÓïÑÔ£¡¼¸ºõÿ¸öÈ˶¼ÓÐÄÜÁ¦½«¶ÌСµÄ´úÂëƬ¶Ï·ÅÈëËûÃÇµÄ HTML Ò³Ãæµ±ÖС£ JavaScript ¿ÉÒÔ½«¶¯Ì¬µÄÎı¾·ÅÈë HTML Ò³Ãæ ÀàËÆÓÚÕâÑùµÄÒ»¶Î JavaScript ÉùÃ÷¿ÉÒÔ½«Ò»¶Î¿É± ......
µ¥Ìåģʽ£¨singleton£©
µ¥ÌåÊÇÔڽű¾¼ÓÔØʱ´´½¨µÄ£¬Äܽ«Ò»ÏµÁÐÓйØÁªµÄ±äÁ¿ºÍ·½·¨×é֯Ϊһ¸öÂß¼µ¥Ôª£¬Âß¼µ¥ÔªÀïÃæµÄÄÚÈÝͨ¹ýµ¥Ò»µÄ±äÁ¿½øÐзÃÎÊ£»
Ò»¸öµ¥ÌåÖ÷Òª·ÖΪÈý²¿·Ö
ÓÃÓÚ·ÃÎÊÄÚ²¿ÐÅÏ¢µÄÈë¿Ú±äÁ¿£¨È磺Sky£©
ÊôÐÔ£¨È磺nickName/age/timeInfo£©
·½·¨£¨È磺sayHello£©
»ù±¾½á¹¹
01
var Sky = {
02
& ......
1. Ò»ÖÖÃæÏò¶ÔÏóÓïÑÔÐèÒª¿ª·¢ÕßÌṩÒÔÏÂËÄÖÖ»ù±¾ÄÜÁ¦¡£
£¨1£©·â×°---°ÑÏà¹ØÐÅÏ¢£¨ÎÞÂÛÊôÐÔ»¹ÊÇ·½·¨£©´æ´¢ÔÚ¶ÔÏóÖеÄÄÜÁ¦¡£
£¨2£©¾Û¼¯---°ÑÒ»¸ö¶ÔÏó´æ´¢ÔÚÁíÒ»¸ö¶ÔÏóÄÚµÄÄÜÁ¦¡£
£¨3£©¼Ì³Ð---ÓÉÁíÒ»¸öÀࣨ»ò¶à¸öÀࣩµÃÀ´ÀàµÄÊôÐÔ»ò·½·¨µÄÄÜÁ¦¡£
£¨4£©¶à̬---±àдÄÜÒÔ¶àÖÖ·½·¨ÔËÐеĺ¯Êý»ò·½·¨µÄÄÜÁ¦¡£
2. °Ñ¶ÔÏóµÄËù ......