Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:00:05+00:00 2026-06-11T02:00:05+00:00

I have a function in my swf file: playSound() which I can call via

  • 0

I have a function in my swf file: playSound() which I can call via jQuery like so:

$.talkToFlash("interfaceSounds").playSound();

whereas ‘talkToFlash’ simply returns the swf file. This part is well documented on here and works fine.

But, how do I pass a parameter?

I believe in JS this would be:

$.talkToFlash("interfaceSounds").playSound('swish.mp3');

But what do I do in AS3?

I tried amending my initial working functions:

function playSound() {
    var s:swishSound = new swishSound; 
    var channel:SoundChannel = s.play();
}
ExternalInterface.addCallback("playSound", playSound);

with this:

function playSound(mp3file) {
   trace(mp3file);
}

But ‘mp3file’ is just empty. I tried

ExternalInterface.addCallback("playSound", playSound(mp3file));

and other variations of this ‘theme’, but nothing seems to work. Am I just struggling with syntax here or this there more to it? Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:00:07+00:00Added an answer on June 11, 2026 at 2:00 am

    Turns out was correct to start with. The error lied somewhere else, I’d forgotten to embed a font :/

    Nevertheless, for those who build a similar thing, here’s the complete Code. I’m also not sure if my method of stopping a track is correct, so any improvements most welcome 🙂

    AS3:

    import flash.external.ExternalInterface;
    import flash.media.Sound;
    import flash.media.SoundLoaderContext;
    import flash.net.URLRequest;
    
    function playTrack(track_name) {
    
        var s:Sound = new Sound();
        soundName.text =track_name;
        track_name = '/path/to/mp3/' + track_name + ".mp3";
        var req:URLRequest = new URLRequest(track_name);
        var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
        s.load(req, context);
        s.play();
    
    }
    
    function stopAllTracks() {
    SoundMixer.stopAll();
    }
    
    ExternalInterface.addCallback("playTrack", playTrack);
    ExternalInterface.addCallback("stopAllTracks", stopAllTracks);
    

    And in jQuery:

    // play a song
      $.curPlay = '';
      $(".song_play").click(function() {    
        var id = $(this).attr('id');
        song = id.replace('play_', '');
        if(song==$.curPlay){  // stop the current song if the play btn is clicked twice
            $.stop_mp3();
            $.curPlay = '';
            return;
        }
    
        $.curPlay = song;
        $.play_mp3(song);
    });
    
    
    
    $.play_mp3 = function(file){ 
        $.stop_mp3();
        $.talkToFlash("interfaceSounds").playTrack(file);   
    }
    
    $.stop_mp3 = function(){  
        $.talkToFlash("interfaceSounds").stopAllTracks();   
    }
    
    
    
    
    //  movie referencer 
    $.talkToFlash = function(swfFile){
    
      if (window.document[swfFile])   {
          return window.document[swfFile];
      }
      if (navigator.appName.indexOf("Microsoft Internet")==-1){
        if (document.embeds && document.embeds[swfFile])
          return document.embeds[swfFile]; 
      }
      else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
      {
        return document.getElementById(swfFile);
      }
    }
    

    And HTML/PHP:

        <div class='song_play'  id='play_<?=$songID?>'>play</div>
    

    I also have a technique that might be worth sharing as I foundd this very usesful when developing with Flash. You can easily change appearance of the container or burst a cache if you set up some vars in PHP that configure your Flash:

    <? 
    $swf = "mp3_player.swf?".time();
    $w = 1;
    $h = 1;
    
    $mp3Player = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8\" 
     codebase = \"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" 
     width=\"$w\" height=\"$h\" id=\"interfaceSounds\" align=\"middle\">
     <param name=\"allowScriptAccess\" value=\"always\" />
     <param name=\"allowFullScreen\" value=\"false\" />
     <param name=\"movie\"  value=\"/assets/swf/$swf\" />
      <param name=\"quality\" value=\"high\" />
     <embed src=\"/assets/swf/$swf\" quality=\"high\" width=\"$w\" 
     height=\"$h\" name=\"interfaceSounds\" align=\"middle\" 
     allowScriptAccess=\"always\"  allowFullScreen=\"false\"
      type=\"application/x-shockwave-flash\"    
     pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />
     </object>";
    

    In your php doc later you just echo it where ever you want:

      <?= $mp3Player ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a SWF file with a simple function that returns a string. can
I am new to JQuery and I have the following issue: Source file: function
I have loaded an external swf file which plays a flv file by default
I have a button in a swf file. I would like that when the
Is there a way to call a function inside a loaded SWF file? Basically,
I have an swf file which behaves strangely on IE. The thing is that
so I have this javascript/jquery to make a delay before showing a swf file,
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function getCartItems in cart.js and I want to call that function in
I have function some_func_1 which will create an object of type some_type and will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.