2012、09、27 听课笔记
相册的制作
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.display.Bitmap;
import flash.events.ProgressEvent;
public class Photos extends Sprite
{
private var loader:Loader;
private var url:URLRequest;
private var num:int=5;
private var str:String;
private var arr_pic:Array=[];
public function Photos():void
{
init();
}
private function init():void
{
for(var i:int=1;i<=num;i++)
{
str='images/'+i+'.jpg';
url=new URLRequest(str);
loader=new Loader();
loader.load(url);
addChild(loader);
arr_pic.push(loader);//数组里放到是加载每个图片的loader
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,oncom);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onpro);
}
}
private function onpro(e:ProgressEvent):void
{
trace(e.bytesLoaded/e.bytesTotal);
}
private function oncom(e:Event):void
{
e.target.loader.width=100;
e.target.loader.height=100;
for(var i:int=0;i<arr_pic.length;i++)
{
arr_pic[i].x=i * arr_pic[i].width+30;//设置图片的X坐标
arr_pic[i].y=300;//设置图片的X坐标
arr_pic[i].addEventListener(MouseEvent.CLICK,onbig);
}
}
private function onbig(e:MouseEvent):void
{
var index:int=arr_pic.indexOf(e.target);
var url_big:String='images/'+(index+1)+'.jpg';
url=new URLRequest(url_big);
loader=new Loader();
loader.load(url);
loader.x=80;
// loader.width = 400;
// loader.height = 300;
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onbigpic);
}
private function onbigpic(e:Event):void
{
e.target.loader.width=400;
e.target.loader.height=300;
}
}
}