我想从嵌入式调用 JavaScript 函数.swf
文件。具体来说,我想从内部调用外部链接的 JavaScript 文件之一中的函数:
function loadTrack(){
//Radio Mode feature by nosferathoo, more info in: https://sourceforge.net/tracker/index.php?func=detail&aid=1341940&group_id=128363&atid=711474
if (radio_mode && track_index == playlist_size - 1) {
playlist_url=playlist_array[track_index].location;
for (i=0;i<playlist_mc.track_count;++i) {
removeMovieClip(playlist_mc.tracks_mc["track_"+i+"_mc"]);
}
playlist_mc.track_count=0;
playlist_size=0;
track_index=0;
autoload=true;
autoplay=true;
loadPlaylist();
return(0);
}
start_btn_mc.start_btn._visible = false;
track_display_mc.display_txt.text = playlist_array[track_index].label;
if (track_display_mc.display_txt._width > track_display_mc.mask_mc._width) {
track_display_mc.onEnterFrame = scrollTitle;
}else{
track_display_mc.onEnterFrame = null;
track_display_mc.display_txt._x = 0;
}
mysound.loadSound(playlist_array[track_index].location,true);
play_mc.gotoAndStop(2)
//info button
if(playlist_array[track_index].info!=undefined){
info_mc._visible = true;
info_mc.info_btn.onPress = function(){
getURL(playlist_array[track_index].info,"_blank")
}
info_mc.info_btn.onRollOver = function(){
track_display_mc.display_txt.text = info_button_text;
}
info_mc.info_btn.onRollOut = function(){
track_display_mc.display_txt.text = playlist_array[track_index].label;
}
}else{
info_mc._visible = false;
}
resizeUI();
_root.onEnterFrame=function(){
//HACK doesnt need to set the volume at every enterframe
mysound.setVolume(this.volume_level)
var load_percent = (mysound.getBytesLoaded()/mysound.getBytesTotal())*100
track_display_mc.loader_mc.load_bar_mc._xscale = load_percent;
if(mysound.getBytesLoaded()==mysound.getBytesTotal()){
//_root.onEnterFrame = null;
}
}
}
它位于 .as 文件中,我认为它以某种方式成为 swf 文件。我该怎么做?re-compile
the .as
file?
让我们使用 JS 注入和ExternalInterface 一起编译 AS2 和 AS3 的这些答案(两种方法都适用于两种语言)
AS2:
// to use javascript injection in a url request
getURL("javascript:displayPost(" + postId + "," + feedId +");", "_self");
// to use the external interface
import flash.external.ExternalInterface;
ExternalInterface.call("displayPost",postId,feedId);
AS3:
// to use javascript injection in a url request
navigateToURL(new URLRequest("javascript:displayPost(" + postId + "," + feedId +");"), "_self");
// to use the external interface
import flash.external.ExternalInterface;
ExternalInterface.call("displayPost",postId,feedId);
请注意,在 AS2 和 AS3 中,ExternalInterface 方法完全相同(ExternalInterface 是在 AS2 的 Flash 8 中引入的)。在AS2和AS3中,javascript注入方法是相同的,只是它是navigateToURL而不是getURL,并且url字符串被包装在new URLRequest()中,因为它需要一个URLRequest对象。此外,在使用 javascript 注入时,最好将目标窗口设置为“_self”以避免打开新选项卡或窗口。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)