体验AS3.0(八)

      Flash 2006-2-14 13:44:00
交互性是FLASH的灵魂,那我们如何在FP8.5实现交互呢?以往我们可以通过添加on(release){} 或 this.onRelease = function(){}之类的语句来和MovieClip进行交互。在AS3.0中,我们必须通过类似以往V2组件的交互方式addEventListener来实现这一功能。
就象我们前面提到的一样,现在我们要用Sprite来代替MovieClip了。
//TEST6.as
package {
  
import flash.events.MouseEvent;
import flash.events.MouseEventType;
import flash.util.trace;
import flash.display.Sprite;


public class Test extends Sprite {

public function Test() {
    addChild( new MySprite());
}

}

private class MySprite extends Sprite
{
  
  public function MySprite(){
    createUI();
  }
  
  private function createUI(){
     graphics.beginFill(0xff0000);
graphics.drawRect(0, 0, 100, 100);
graphics.endFill();

useHandCursor = true;
addEventListener( MouseEventType.MOUSE_UP, mouseListener);
  }
  
public function mouseListener( evt:MouseEvent){
trace( "Test::mouseListener " + this + ":" + evt);
}
  
}

}
同AS2.0中的addEventListener比较一下,我们不再需要用Delegate.create将一个function绑定到handler上,这大大简化了我们的编码过程。
标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}
深度XP 雨林木风XP WinXP下载 世界之窗 深度系统 雨林木风 Ghost ghost系统盘 XP下载