user547794
user547794

Reputation: 14511

AS3 - ExternalInterface.addCallback, Access of undefined property

I am trying to use javascript to run AS3 functions. When I attempt to compile I'm getting an "Access of undefined property" error message.

I've read a few things online about this but I'm still not understanding it. I want to have the flash file always listening for javascript.

Here is my AS3 code:

ExternalInterface.addCallback("song4", PauseMusicExt);

And my Javascript & HTML:

 function returnVar3(song3) { return this[song3]; }
  <input type="submit" name="playButton" id="playButton" value="Submit" onClick="returnVar('song3')"/>

Edit: Here is the pauseMusic function:

function pauseMusicExt():void
    {
        songPosition = channel.position;
        channelSilence.stop();
        channel.stop();
        channel2.stop();
        btnPlay.mouseEnabled = true;
    }

Upvotes: 0

Views: 8897

Answers (2)

Ben
Ben

Reputation: 21249

I'm not sure about the extend of your app but you've got your addCallback function parameters mixed up..

See the doc, the first parameter is the name you want to expose the function as to javascript, the second is the actual internal AS3 function you want to trigger.

So the declaration should likely be something like:

ExternalInterface.addCallback("song4", pauseMusic);

(assuming that your function in the same scope as where you call addCallback)

That statement will create a "song4" method that you can call on your flash dom object

var fl = document.getElementById('myflashobject');
fl.song4()

After there's the issue that pauseMusic want a parameter (looks like you've made it a mouse event handler). You probably want to have a clean method that doesn't require a parameter like an internal as3 event param. Rewrite pauseMusic so it doesn't require it (you might need to create another method to handle the mouse event internally - like onPause(evt:MouseEvent), which then calls pauseMusic.

Edit: I don't know if a lot of people thought about doing that, but you can also totally use external interface to call firebug's console.log function to send messages to Firebug from flash (it's really helpful for debugging ExternalInterface issues, or any other flash problems - see the ExternalInterface.call function)

Upvotes: 4

Benny
Benny

Reputation: 2228

Hope u want to pause the audio player.

AS code :

 ExternalInterface.addCallback("sndToAS",rcvdFmJS);
    function rcvdFmJS(val){
       if (val == "pause"){
      audioPause();
       }
    }

JS code :

    document.getElementById("movie").sndToAS("pause");    

Upvotes: 0

Related Questions