Archive for the ‘ActionScript’ Category

  • 方法如下:

    override public function dispatchEvent(evt:Event):Boolean {
     	if (hasEventListener(evt.type) || evt.bubbles) {
      		return super.dispatchEvent(evt);
      	}
     	return true;
    }

    好处吗?当然是性能,hasEventListener可要比dispatchEvent速度快N倍,如果你的项目中有大量的Event要被长时间分发,性能的优势就看出来了 。

  • Google As3 API ,三方开发的,粉不错。

    地址:http://labs.boulevart.be/index.php/2008/12/15/google-as3-api/

    This api contains:

    • Google Web Search
    • Google Images Search
    • Google Book Search
    • Google Video Search (Google Video & YouTube)
    • Google Blog Search
    • Google Local Search
    • Google Patent Search
    • Google News Search
    • Google Translation (new)

    This API is Flash & Flex compatible.

    现在As3的AIP真的是一天可以出现一筐,只是可惜现在的应用开发速度完全跟不上类库的发展。

    泡沫经济会引发金融风暴,真不知道这种“泡沫科技”最后会怎么样。

  • ApplicationDomain应该怎么用,文档都看了800多次了,就是记不住,没办法,天生的记忆力弱,这东西又不经常用。

    干脆总结一下写出来,以后如果再忘记,也不用去查文档了。

    new ApplicationDomain(ApplicationDomain.currentDomain) = Child可以直接使用Parent的Class,Parent则不可直接调用,必须是私用ApplicationDomain.getDefinition()来调用。

    ApplicationDomain.currentDomain  = Child和Parent可以任意使用对方的Class(Class重名会冲突)。

    new ApplicationDomain(null) = Child和Parent将使用自己的Class(Class重名不会冲突),如果一方要调用另一方的Class,要使用ApplicationDomain.getDefinition()。推荐用这种,麻烦就麻烦吧,起码可控性高。

     

  • 一直以来,如果需要加载另外一个SWF,并与之互动的话,都是用Adobe文档中的

    Loader.contentLoaderInfo.applicationDomain.getDefinition(className)

    今天猛然发现,原来Loader加载完成后,是可以直接调用原SWF中的方法以及舞台上的对象:

    1.新建一个target.fla,第一帧代码如下

    function method():void{
    trace("Function on ActionSctipt");
    }
    

    2.在target.fla的舞台上放置一个文本,取名为textOnStage

    3.编译好target.swf文件

    4.加载target的SWF使用下面的代码作为文档类

    package
    {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
    
    public class T1 extends Sprite
    {
    private var loader:Loader = new Loader();
    
    public function T1()
    {
    var req:URLRequest = new URLRequest("target.swf");
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
    loader.load(req);
    }
    
    public function onComplete(e:Event):void{
    Object(loader.content).method();//如果能确定loader.content类型的话,可以直接用类型代替Object,如MovieClip(loader.content)
    trace(Object(loader.content).textOnStage.text);
    }
    
    }
    }
    
  • 直接在Flash Cs4下跑

    var i : uint;
    var t : uint;
    var length : uint = 1000000;
    
    //test Vector
    t = getTimer();
    
    var v:Vector.<String> = new Vector.<String>(length, true);
    for( i = 0; i < length; i ++ )
    {
    v[i] = “1″;
    }
    
    trace(getTimer() - t);
    
    //test Array
    t = getTimer();
    
    var a:Array = new Array();
    for( i = 0; i < length; i ++ )
    {
    a[i] = “1″;
    }
    
    trace(getTimer() - t);
    
  • 1.Vector是为了增加性能而出现的

    2.Vector指定元素类型是为了增加性能

    3.Vector指定长度是为了增加性能

    4.Vector的用法是:

    var v:Vector.<String> = new Vector.<String>(length, fixed);
  • visible ,alpha和removeChild()都可以让对象从舞台上“消失”。

    但是哪种更好呢?或者说哪种方式更适合于什么情况下使用呢?

    这里有篇文章做了详尽的分析

    http://www.insideria.com/2008/11/visible-false-versus-removechi.html

    作者很强大,排列组合了所有的可能性,然后分析,最后的结论是:

    如果对象真的是不用了,那就removeChild()吧,

    如果以后还要用,而且还要照顾到深度管理的问题,那就用visible,

    基本上,Alpha=0是不需要用到的。

  • package
    {
    	import flash.display.Bitmap;
    	import flash.display.BitmapData;
    	import flash.display.Loader;
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.geom.Matrix;
    	import flash.net.URLRequest;
    	import flash.text.TextField;
    
    	public class Example00 extends Sprite
    	{
    		private var load:Loader;
    
    		public function Example00()
    		{
    			super();
    
    			load = new Loader()
    			var req:URLRequest = new URLRequest("http://i3.sinaimg.cn/home/deco/2008/0325/sinahome_Logo.gif")
    			load.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoad)
    			load.load(req);
    			addChild(load);
    
    		}
    
    		public function onLoad(e:Event):void{
    			var tf:TextField = new TextField();
    			tf.text = "Flash复制对象的Bitmap";
    			addChild(tf);
    
    			var bounds:Object = this.getBounds ( this );
    
    			var mat:Matrix = new Matrix();
    			mat.translate ( -bounds.x, -bounds.y );
    
    			var buffer:BitmapData = new BitmapData ( this.width+1, this.height+1, true, 0 );
    
    			buffer.draw ( this, mat );
    
    			var newBuffer:Bitmap = new Bitmap(buffer)
    
    			addChild(newBuffer)
    
    			newBuffer.x = 100
    			newBuffer.y = 200
    		}
    
    	}
    }