Tuesday, September 13, 2011

[Flash][Debug][Javascript] Debug Flash App on Web Page

Sometimes I found Debugging a Flash App is a big headache. I don't want to always check the Flash Player's log (it logs everything) and I don't want to setup the Flash Player Debug, there's always some problems if you use a different OS or reinstalled your OS. I found the following method efficient if you want to find out what is happening with your Flash App on a web page.

The basic idea is a call from your Flash App to Javascript and Javascript set the received value to a textarea on the html page. So as you go (play your Flash App), you can see your debug message instantly on the textarea within the same page).

On your page, add a javascript function to set the received string to the textarea. And a form with a textarea in html to display the received string:

function getTextFromFlash(str) {

document.htmlForm.receivedField.value += str + "\n";

}


<textarea rows="10" cols="20" name="receivedField"></textarea>


In flash, import the ExternalInterface and then use that to make a call to the Javascript function:

import flash.external.ExternalInterface;

ExternalInterface.call("getTextFromFlash", "Your message");

0 comments: