The most basic Method:
There is one fairly simple method, just adding two lines:
import flash.external.ExternalInterface;
ExternalInterface.call( "console.log" , "Hey! I'm tracing from Flash!");
Well, you should notice that, since the javascript code would not be executed when opening the HTML file in browser from local disc, you must put the HTML and SWF file on a Web server, and access it with browers.
My first try on AS3commons logging:
Download the swc from:
http://code.google.com/p/as3-commons/downloads/detail?name=as3commons-logging-2.7.swc
and add it to .fla lib path:
According to the guide at: http://www.as3commons.org/as3-commons-logging/userguide.html,
I start with the code:
package {
import flash.display.MovieClip;
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getLogger;
import org.as3commons.logging.api.LOGGER_FACTORY;
import org.as3commons.logging.setup.target.*;
import org.as3commons.logging.setup.SimpleTargetSetup;
public class main extends MovieClip
{
public function main()
{
LOGGER_FACTORY.setup = new SimpleTargetSetup(new FirebugTarget());
getLogger("myLogger").info("Some logging message");
trace("reach here");
}
}
}
The error I got is:
1046: Type was not found or was not a compile-time constant: Base64Encoder.
Here is online doc on Base64Encoder: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/Base64Encoder.html
I tried to import the class by adding line: "import mx.utils.Base64Encoder;", but I got error saying that it could not be found. Since it was stated that this class is within Flex library, I thought it might be shipped with Flex SDK package, but after downloading the package, I found nothing I need within that over-200 mb-size bulk.
However, before I gave up, I found the two source-code ASs here: http://code.google.com/p/katopz/source/browse/trunk/as3/libs/mx/utils/?r=1317,
I saved them, and put them under my project directory, and now the code should be:
package {
import flash.display.MovieClip;
import mx.utils.Base64Encoder;
import org.as3commons.logging.api.ILogger;
import org.as3commons.logging.api.getLogger;
import org.as3commons.logging.api.LOGGER_FACTORY;
import org.as3commons.logging.setup.target.*;
import org.as3commons.logging.setup.SimpleTargetSetup;
public class main extends MovieClip
{
public function main()
{
LOGGER_FACTORY.setup = new SimpleTargetSetup(new FirebugTarget());
getLogger("myLogger").info("Some logging message");
trace("reach here");
}
}
}
And publish the SWF with HTML, upload them to server docs folder, then access the html from Firefox:
Refs:
http://osflash.org/projects#logging_tools
AS3commons logging
Configure the debugger version of Flash Player