1

I am making flash player that suppose to be controlled from outside, from javascript.

I need those methods: Play/Pause and Volume level

I am stuck with volume level... I tried to add this code:

flashMovie.volume = 10;

Where flashMovie is flash instance... And it's show NO ERROR but it's NOT WORKING

I try to make inner AddCall(); and then when it's called to call() from javascript to return sound level.

AS 3:

function setthisvolume()
{
        var vlm = ExternalInterface.call('giveMeVolume()');
        this.soundTransform.volume = vlm;
}

ExternalInterface.addCallback("setthisvolume", setthisvolume);

JS:

var soundlevel = 10;

function soundlevelset()
{
    var flashMovie=getFlashMovieObject("objswf");
    flashMovie.setthisvolume();

}

function giveMeVolume()
{
    return parseInt(soundlevel);
}

But I am getting this error:

Error calling method on NPObject!

I even tried with setInterval():

AS 3:

function setthisvolume()
{
        var vlm = ExternalInterface.call('giveMeVolume()');
        this.soundTransform.volume = vlm;
}

setInterval(setthisvolume, 1000);

JS:

var soundlevel = 10;

function giveMeVolume()
{
    return parseInt(soundlevel);
}

And it doesn't show any error, but it doesn't work neither...

Did someone work with stuffs like this?

Can someone help me what I am doing wrong here...

Thank you!

1
  • Correct code is in my answer... ;) Commented Sep 18, 2011 at 12:15

3 Answers 3

2

Thank you, @someone! This second option worked okay!

Here is working code:

AS3:

function setthisvolume(vlm)
{
        this.soundTransform = new SoundTransform(vlm);
}

ExternalInterface.addCallback("setthisvolume", setthisvolume);

JS:

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}

var soundlevel = 0.5;                  // it's 0-1 volume, not 0-100
function soundlevelset()
{
    var flashMovie=getFlashMovieObject("objswf");
    flashMovie.setthisvolume(parseFloat(soundlevel));
}

When you are using slider each time slider change you need to change soundlevel variable and call soundlevelset();

Hope I helped next one who is starting with this... :)

Thank you!

Sign up to request clarification or add additional context in comments.

Comments

1

Try removing the parentheses when calling giveMeVolume, by changing this:

var vlm = ExternalInterface.call('giveMeVolume()');

to this:

var vlm = ExternalInterface.call('giveMeVolume');

If that doesn't work, try passing the volume directly as an argument/parameter, like this (this is probably a better way to do it):

AS3:

function setthisvolume(vlm)
{
        this.soundTransform.volume = vlm;
}
ExternalInterface.addCallback("setthisvolume", setthisvolume);

JS:

var soundlevel = 10;
function soundlevelset()
{
    var flashMovie=getFlashMovieObject("objswf");
    flashMovie.setthisvolume(soundlevel);
}

Comments

1

Code looks reasonable.

Check if you allow Flash to communicate with script There is property when you create Flash object - AllowsScriptAccess - http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c9b.html .

Check if Falsh is coming from the same domain as HTML page.

For addCallback check if you are getting correct Flash object by Id (the way to create Flash is different in IE/FF, so you may be getting the wrong one).

Check if you have correct SWF file - browser may cache older version... I.e. add element on the Flash control that simply shows static number and make sure it matches to latest one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.