2

AS3:

ExternalInterface.addCallback('getParams', getParams);
function getParams()
        {
            var params:Array = new Array();
            for(i = 0; i < images.length; i++)
            {
                params.push(picWin.getChildAt(i));
            }

            return params;
        }

JS:

$('#button').click(function(){

        var res = document.getElementById("swfobject").getParams();
        alert(res);

    })

So after i get an error of some NPO object error, can't figure it out what it means, but if I pass an array itself its ok, if I pass an object itself it will be also ok, but when i pass an array of objects it gives me an error NPO, how to fix this?

2
  • also it happens when i try to pass an object with objects within Commented Dec 14, 2012 at 1:29
  • your return within AS is only within AS. In order to send something back to JS you need to use ExternalInterface.call(); Commented Dec 14, 2012 at 1:36

1 Answer 1

2

To pass from AS to JS you want to use

ExternalInterface.call("myJsFunction", myArray);

for this example, you need 2 JS functions: the first handles the click and sends a request to your swf. The second is called by the swf with your return value:

AS3:

ExternalInterface.addCallback('getParams', getParams); // listens for JS to getParams 
function getParams()
    {
        var params:Array = new Array();
        for(i = 0; i < images.length; i++)
        {
            params.push(picWin.getChildAt(i));
        }

        ExternalInterface.call("handleParams", params); // calls a js function and passes params 
    }

JS:

$('#button').click(handleClick)

function handleClick(event){
    document.getElementById("swfobject").getParams(); //sends request to swf
}

function handleParams(params){ // handles response from swf
     alert("You got an array with " + params.length + " elements back from flash.");
}
Sign up to request clarification or add additional context in comments.

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.