图片转换AS2.0类(实用型)

2008-04-02 11:02:59来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


  先看看效果:

  http://public.iecn.net/freebrandy/ShowImage/ShowImagesIII.swf

  改进过程

  http://public.iecn.net/freebrandy/ShowImage/ShowImages.swf

  http://public.iecn.net/freebrandy/ShowImage/ShowImagesII.swf


  源文档下载:picchange.rar

  AS类代码:

  
import mx.events.EventDispatcher;

  class ShowImages extends MovieClip {

  private var myUrl:Array; //存放图片路径的数组

  private var myInfo:Array; //存放图片信息的数组

  private var showImageBox:MovieClip; //图片显示区域

  private var myLoading:MovieClip //加载图片的MC

  private var topMC:MovieClip; //顶部MC

  private var buttonMC:MovieClip; //底部MC

  private var currentTopMC:MovieClip; //记录当前在较高深度的MC

  private var allowToPlayImage:Boolean = true;

  private var _id:Number; //定时器ID

  private var _showtime:Number = 3000; //定时器时长

  private var imageID:Number = 0; //自动播放时保存图片ID值

  private var myMask:MovieClip; //遮罩MC

  private var ImageDepth:Number=100; //放置图片MC的深度

  private var firstLoadImage:Boolean = true; //是否第一次载入图片

  //private static var loaderTextFormat:TextFormat = new TextFormat("Arial", null, 0x000000, true);

  public var addEventListener:Function;

  public var removeEventListener:Function;

  private var dispatchEvent:Function;

  private static var _mixin1 = EventDispatcher.initialize(ShowImages.prototype);

  public function ShowImages() {

  fscommand("allowscale",false);

  fscommand("showmenu",false);

  }

  private function onLoad():Void {

  //定位至原点

  _x = _y = 0;

  //添加侦听事件

  addEventListener("onPhotoListLoad", this);

  //导入存放图片的XML文档

  myUrl = new Array();

  //myInfo = new Array();

  var me:Object = this;

  var my_xml = new XML();

  my_xml.ignoreWhite = true;

  my_xml.load("PhotoList.xml");

  my_xml.onLoad=function(success){

  if (success){

  //数组值添加

  var xmlA:Array = this.firstChild.childNodes;

  var xmlALen:Number = xmlA.length;

  for (var i = 0; i<xmlALen; i ) {

  me.myUrl.push(xmlA[i].attributes.myUrl);

  //me.myInfo.push(xmlA[i].attributes.myInfo);

  }

  //发出事件给自身

  me.dispatchEvent({type:"onPhotoListLoad", target:this});

  }

  }

  }

  private function onPhotoListLoad():Void {

  //先建立放图片的的MC

  showImageBox = this.createEmptyMovieClip("showImageBox",ImageDepth);

  myLoading = showImageBox.createEmptyMovieClip("myLoading",ImageDepth 20);

  topMC = showImageBox.createEmptyMovieClip("topMC", ImageDepth 10);

  //topMC._x = 200;

  buttonMC = showImageBox.createEmptyMovieClip("buttonMC", ImageDepth);

  //导入图片(loadImage是自循环式函数)

  loadImage();

  }

  private function loadImage():Void {

  //先取消定时器

  clearInterval(_id);

  //取得对象自身,方便访问

  var thisObject:Object = this;

  //循环控制(这里使用变换深度然后配置遮罩的方法)

  if ( imageID == myUrl.length ) imageID = 0;

  //第一次载入图片时无需交换深度

  if (firstLoadImage){

  currentTopMC = topMC;

  firstLoadImage = false;

  }else{

  //先交换深度

  topMC.swapDepths(buttonMC);

  //再决定谁在上面

  if ( topMC.getDepth() > buttonMC.getDepth() ){

  currentTopMC = topMC;

  }else{

  currentTopMC = buttonMC;

  }

  }

  //在上面的MC导入图片,因为遮罩只对处在上面的MC

  currentTopMC.loadMovie(myUrl[imageID]);

  //trace(topMC.getDepth());

  imageID ;

  //导入图片

  myLoading.onEnterFrame = function() {

  var lb:Number = thisObject.currentTopMC.getBytesLoaded();

  var tb:Number = thisObject.currentTopMC.getBytesTotal();

  var percent:Number = Math.round(lb/tb*100);

  if (percent == 100 and thisObject.currentTopMC.getBytesLoaded()>100 and thisObject.currentTopMC._height>0){

  //特效显示图片

  thisObject.showOff(thisObject.currentTopMC);

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: 制作Flash网站技巧拾零

下一篇: FlashAS用在功课上:解决一道高中数学题