Actionscript3.0 Logging with FlashPlayer

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:

add-swc-to-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:

as3commons-with-firebug





Refs:


http://osflash.org/projects#logging_tools

as3-commons


AS3commons logging


flash在瀏覽器上記錄trace出來值的log

Configure the debugger version of Flash Player






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值