当前位置:软件学习 > Flash >>

flash实现背景移动

flash实现背景移动package cn.flash023{
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class Ving extends Sprite {
  private var show_sprite:Sprite;
  private var point:uint;
  public function Ving():void {
   show_sprite=new Sprite;
   point =new uint;
   init();
  }
  private function init():void {
   addChild(show_sprite);
   for (var p:uint=0; p<9; p++) {
    var _pinging=new Ping(String(p+1));
    _ping.x=p%3*550,_ping.y=uint(p/3)*400;
    show_sprite.addChild(_ping);
    _ping.addEventListener("live",onClick);
   }
  }
  private function onClick(_evt:MouseEvent):void {
   var _pinging =_evt.target as Ping;
   point!=_ping["_btnmode"]&&show_sprite.addEventListener ("enterFrame",moveShow);
   point=_ping["_btnmode"];
  }
  private function moveShow(_evt:Event):void {
   var _sprite:Sprite=_evt.target as Sprite;
   _sprite.x+=(-point%3*550-_sprite.x)*.2;
   _sprite.y+=(-uint(point/3)*400-_sprite.y)*.2;
   Math.abs (-point%3*550-_sprite.x)<.2&&Math.abs (-uint(point/3)*400-_sprite.y)<.2&&_sprite.removeEventListener ("enterFrame",moveShow);
  }
}
}

package cn.flash023{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.controls.Button;
import flash.text.TextField;
public class Ping extends Sprite {
  public var _btnmode:uint;
  public function Ping(_l:String=""):void {
   label_txt.text=_l;
   _btnmode=new uint;
   init();
  }
  private function init():void {
   for (var _p:uint=0; _p<numChildren; _p++) {
    var _btn:Button =getChildAt(_p) as Button;
    if (_btn) {
     _btn.label =String(_p);
     _btn.addEventListener("click",onClick);
    }
   }
  }
  private function onClick(_evt:Event):void {
   var _btn:Button =_evt.target as Button;
   _btnmode=uint(_btn.label)-1;
   dispatchEvent(new MouseEvent("live"));
  }
}
}

补充:flash教程,As3.0
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,