最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ActionScript + JavaScript - Stack Overflow

programmeradmin2浏览0评论

I'd like to call a JavaScript function from an embedded .swf file. Specifically, I'd like to call a function in one of my externally linked JavaScript files from within:

function loadTrack(){

    //Radio Mode feature by nosferathoo, more info in: .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 an .as file which I assume somehow bees the swf file. How would I go about this and re-pile the .as file?

I'd like to call a JavaScript function from an embedded .swf file. Specifically, I'd like to call a function in one of my externally linked JavaScript files from within:

function loadTrack(){

    //Radio Mode feature by nosferathoo, more info in: https://sourceforge/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 an .as file which I assume somehow bees the swf file. How would I go about this and re-pile the .as file?

Share Improve this question edited Sep 28, 2020 at 21:52 Alex 1,5801 gold badge15 silver badges27 bronze badges asked Apr 16, 2009 at 18:14 danwoodsdanwoods 4,90711 gold badges65 silver badges93 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

Let's pile those answers together for AS2 and AS3 using JS injection AND the ExternalInterface (both ways 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);

Notice that in AS2 and AS3 the ExternalInterface method is the exact same (ExternalInterface was introduced in Flash 8 for AS2). And in AS2 and AS3 the javascript injection method are the same except that it's navigateToURL instead of getURL, and the url string is wrapped in new URLRequest(), because it needs a URLRequest object. Also when using javascript injection, it's a good practice to set the target window to "_self" to avoid a new tab or window from opening.

Also incase anyone in the future is looking at this question the Actionscript 3 version of altCognito's answer is like this:

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

From:

  • http://www.klynch./archives/000079.html

You can also look into the following:

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

发布评论

评论列表(0)

  1. 暂无评论