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

flash用加载图片来填充mc实现代码

 代码如下 复制代码

填充某个mc
------------*/
import flash.display.BitmapData;
import flash.geom.*;
//画矩形
function createRectangle(x:Number, y:Number, w:Number, h:Number, mc:MovieClip) {
 mc.moveTo(x, y);
 mc.lineTo(x+w, y);
 mc.lineTo(x+w, y+h);
 mc.lineTo(x, y+h);
 mc.lineTo(x, y);
 mc.endFill();
}
//mcTarget:MovieClip 要填充的影片 mcDraw:MovieClip 填充的素材 strMask 遮蔽,要填充的影片里的影片名字
function FillBmpMc(mcTarget:MovieClip, mcDraw:MovieClip, strMask:String) {
 var rect_mc:MovieClip = mcTarget.createEmptyMovieClip("rect_mc", mcTarget.getNextHighestDepth());
 rect_mc.bmp = new BitmapData(20, 20, false);
 rect_mc.bmp.draw(mcDraw);
 rect_mc.beginBitmapFill(rect_mc.bmp);
 //因为只能填充一下用程序画的图形。
 createRectangle(0, 0, mcTarget._width, mcTarget._height, rect_mc);
 //如果填充一个不规则的图形,就要在要填充的影片里放一个作遮蔽的影片,不用的话,传一个没有申明的变量就可以了。
 if (strMask != undefined) {
  rect_mc.setMask(mcTarget[strMask]);
 }
}
//获得文件路径
function getFilePath():String {
 var arrA:Array, strRen:String, strSplit:String;
 strSplit = "/";
 arrA = _root._url.split(strSplit);
 if (arrA.length == 1) {
  strSplit = "\";
 }
 for (var i:Number = 0; i<arrA.length-1; i++) {
  if (i == 0) {
   strRen = arrA[0];
  } else {
   strRen += strSplit+""+arrA[i];
  }
 }
 strRen += strSplit;
 return strRen;
}

//提示框
function talkYou(strA:String){
 txtTalkYou.text=strA
}
//
var mcImg:MovieClip = _root.createEmptyMovieClip("mcImg", _root.getNextHighestDepth());
var mcImg2:MovieClip;
//加载图片 MovieClipLoader  侦听对象
var objLoad:Object = new Object();
objLoad.onLoadInit = function(target_mc:MovieClip) {
 //talkYou("加载完成,第一帧");
 talkYou("");
 //没有遮蔽
 FillBmpMc(canvas, target_mc, strMask);
 //有遮蔽
 FillBmpMc(mcMask, target_mc, "mcMask");
 //利用完了就搞死它:P
 target_mc.removeMovieClip();
};
objLoad.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number) {
 talkYou("完全下载");
};
objLoad.onLoadError = function(target_mc:MovieClip, errorCode:String, httpStatus:Number) {
 talkYou("未能加载");
};
objLoad.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
 talkYou("加载过程中.."+Math.floor((loadedBytes/totalBytes)*100)+"%");
};
objLoad.onLoadStart = function(target_mc:MovieClip) {
 talkYou("开始下载");
};
var myLoader:MovieClipLoader = new MovieClipLoader();
myLoader.addListener(objLoad);
//加载图片路
myLoader.loadClip(getFilePath()+"test.jpg", mcImg);

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