Actionscript + javascript

I would like to call the javascript function from the embedded .swf file. In particular, I would like to call a function in one of my external javascript files from the inside:

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; } } 

}

which is in the .as file, which I assume becomes a swf file. How can I do this and compile the .as file?

+1
source share
3 answers

Compile these answers together for AS2 and AS3 using JS injection AND ExternalInterface (both methods work in BOTH languages)

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); 

Note that in AS2 and AS3, the ExternalInterface method is the same (ExternalInterface was introduced in Flash 8 for AS2). And in AS2 and AS3, the javascript injection method is the same, except that it navigateToURL instead of getURL, and the url string ends in a new URLRequest () because it needs a URLRequest object. Also, when using javascript injection, it is recommended to set the target window to "_self" so as not to open a new tab or window.

+7
source

Also, if anyone in the future looks at this question, the version of the ActionScript 3 Altcript response is as follows:

 ExternalInterface.call("displayPost",postId,feedId); 
+3
source
  getURL("javascript:displayPost(" + postId + "," + feedId +")"); 

From:

You can also see the following:

http://osflash.org/projects/flashjs/tutorials/jstoas

+2
source

All Articles