vendredi 25 novembre 2016

calling actionscript 3 function from javascript with addCallback not working

I have a requirement in a project which has to call an actionscript 3 function from javascript. I read many answers from stackoverflow and adobe and have created a simple test application. In that, I have used ExternalInterface.addCallback to register both the functions and I've also included the security permissions in both actionscript and in html.

Action Script 3 Embedded code

I did not use an external .as file instead i used the action panel to create the code.

import fl.controls.Button


var butt:Button = new Button();

butt.label = "hello";
butt.toggle = true;
butt.move(50, 50);
butt.height = 100;
butt.addEventListener(MouseEvent.CLICK, clickhandle);

function clickhandle(e:MouseEvent)

        if(butt.height == 100)
            butt.height = 200;
        else butt.height = 100;


ExternalInterface.addCallback("callas", clickhandle);

The test app will display a ac3 button. Upon clicking that button it will toggle the expanding and collapsing of its height through a click handler 'clickhandle'. This is the function i am intended to call from javascript.


function callas() {
    var hehe = document.getElementById('cvpanel');

<object id='cvpanel' name='cvpanel' width="425" height="350" type="application/x-shockwave-flash" data="one.swf">
    <param value="one.swf" name="movie">
    <param name="allowscriptaccess" value="always"/>
    <p>You need Flash to see it.</p>

The application runs under http://localhost through apache and all the files needed are in the same folder. I could run the application and could see the buttons appearing. By clicking it they toggle in height as expected.

When i call the function callas from browser console i get the error in console as

"TypeError: hehe.clickhandle is not a function"

in firefox and similar in Internet Explorer.

Is there anything missing?

Aucun commentaire:

Enregistrer un commentaire