Flash does not execute Javascript code which is embedded in php

I am new to this forum. Tried all ways to get this working and finally gave up and posting in this forum to see if someone can help me

Here is the problem
I am calling a php file from my flash. This php page has javascript embedded in it. When I execute my php file separately or from another php page, the javascripts get executed. However when the same php file when called from flash ignores the javascript part and does not execute it. It only executes the php portion. I am clueless as to why it behaves like this. Even a simple alert would not work!

Any help is appreciated.


Yeah, you want to use ExternalInterface.call(): http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html

ExternalInterface.call() allows you to call a Javascript function which is in the page that the Flash file is embedded.

So, for example, if that page had a function called updateScore(score), you could use:

ExternalInterface.call("updateScore", 5);

from within your Flash.

Be sure to wrap any ExternalInterface calls in:

if(ExternalInterface.available) {


so you don’t get any runtime errors if it isn’t available for some reason.

Hope that helps.

Thanks for the help.

Here is the scenario. I have a flash library which makes the call to the php page(score.php) The flash library which calls the php page, is being used by hundreds of flash files. The flash files (that use the libray), have similar functionalities where in they have buttons. If I click on these buttons from any of the hundred files, they access the database and access the details for the person who has logged in and updates the database as to whether they have answered the questions correctly or not via the php page(score.php)

The php page(score.php) accesses the database and returns variables within flash and the variables are displayed right now inside flash page. These flash pages are being embedded inside another php page(embed.php)

So far so good. I am able to retrieve the variables from the db and able to display in flash.

What more do I want to do is, for every person who has logged in, I need to provide other details. But these I want to be displayed on the php page (embed.php) on which the flash is embedded.

Like if a person has scored 100 points, I want to display a star.
So I thought of displaying it on a div tag, which I am refreshing every time the user presses a button from flash. But since the div tag can be accessed only using javascript code, I am in trouble. My div tag is not getting refreshed!

This is the issue I am trying to resolve and to do this, I tried doing a sample as given above and it did not work.

Essentially I want to refresh a div tag from my php page, for every button click in flash (But this has to be done with my existing flash file and without recompiling my flash file)

Is there anything I can do other than what you have suggested?

I hope I am clear.

Thanks for your patience and help

^ What he said.

What is the scenario that you are trying to implement? If you’re trying to have the Javascript execute something and output it, you should just use PHP to do so.

If you want the Javascript to do something on your page, you should embed that Javascript into the page the SWF is embedded in and use ExternalInterface to access it.

If you want the Flash to call a PHP file to generate Javascript and then execute it, you could have the Flash call a Javascript function in the page the SWF is embedded which creates an iframe that loads the PHP page and then use ExternalInterface to call the Javascript from there.

If you have to consider using the third method… you may want to re-examine your goal and see if there is a simpler way to achieve the same result.

Anyone please!

Here is the sample that I am trying to execute. I have a flash file which is embedded in a html page
THe flash file has a button for which the on(press) is written as

var select_lv:LoadVars = new LoadVars();
select_lv.onLoad = function(success)
if (success)


select_lv.sendAndLoad("/server/test.php", select_lv, "GET");


The test.php code is something like this

$alertThis = ‘<script>alert(“Alert”);</script>’;
echo $alertThis;

It need not be alert, it can be any js code. I have tried various combinations, but nothing happens.

Again this is a sample I am trying to execute and if this works, then I can implement the js functionality required within my php file

Please note that I do not want my flash calling javascript directly!
Thanks for your help

Can you post some code please. Not sure if i can help buy it may help others help you.

A swf cannot directly interpret javascript. All you’ve done is load some javascript as a text string into a variable within flash. It won’t execute it. If you pass it to the browser using externalInterface then the browser can act on it, as long as the swf embedding parameters allow it.

Thank you!
I shall implement this and let you know if I have problems

You either need to recompile your swf or do it entirely outside flash i.e have a javascript poll the php backend via ajax for score changes and update the div