as3动态加载多张图片,自动缩放并加鼠标边框![新手]
2010-02-12 10:44
387 查看
/***imgload.as*****/
package{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.display.MovieClip;
public class imgload extends Sprite
{
private var list:Array,img:Array;
private var v_width:int=92;
private var v_height:int=107;
private var count:Number=0;
public function imgload():void
{
list = new Array();
img = new Array();
}
public function loadImg(str:String):void
{
list = str.split(',');
for(var i:int=0;i<list.length;i++)
{
var loadimg:Loader = new Loader();
loadimg.name = "loadimg"+i;
var url:String = "image/t"+list[i]+".jpg";
loadimg.load(new URLRequest(url));
img.push(loadimg);
}
addListen(img);
}
public function addListen(loadarry:Array):void
{
for(var i:int=0;i<loadarry.length;i++)
{
loadarry[i].contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
}
}
public function onLoadComplete(e:Event):void
{
var l:Loader = e.target.loader;
var n_width:int = l.content.width;
var n_height:int = l.content.height;
var n_num:Number = v_width/v_height;
var t_width:int = n_width;
var t_height:int = n_height;
var rate:int;
var n_state:Boolean = n_width>v_width || n_height>v_height ? true:false;
if(n_state)
{
if(n_width/n_height>n_num)
{
rate = n_width/v_width;
t_width = v_width;
t_height = n_height/rate;
}
else if(n_width/n_height<n_num)
{
rate = n_height/v_height;
t_height = v_height;
t_width = n_width/rate;
}
}
l.content.width=t_width-2;
l.content.height=t_height-2;
l.content.x = 1;
l.content.y = 1;
var boxmc:imgbox = new imgbox();
boxmc.width = t_width;
boxmc.height = t_height;
boxmc.alpha=0;
var mc:MovieClip = new MovieClip();
mc.addChild(boxmc);
mc.width=t_width;
mc.height=t_height;
mc.addChild(l);
mc.x=100;
mc.y=count;
mc.addEventListener(MouseEvent.MOUSE_OVER,function(){boxmc.alpha=100;mc.buttonMode=true;mc.useHandCursor=true;});
mc.addEventListener(MouseEvent.MOUSE_OUT,function(){boxmc.alpha=0;});
addChild(mc);
count = count+t_height;
}
}
}
/***index.fla 第一针.***/
var str:String = "1024,1226,1428,newyearLogo";//图片列表.因为我做的是php+as通信所以这个地方的参数以后是由php来完成的.当 然试验的时候图片的名字为 t1024.jpg,t1226.jpg,t1428.jpg,tnewyearLogo.jpg并放在image文件夹里.
var k:imgload = new imgload();
k.loadImg(str);
addChild(k);
/***库里的文件:***/
mc名-> imgbox [类名:imgbox]
说明:这个imgbox主要是用来做那个鼠标边框的,就是那个蓝色的边框...如果我能做出蓝色+亮色的效果就炫了.
package{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.display.MovieClip;
public class imgload extends Sprite
{
private var list:Array,img:Array;
private var v_width:int=92;
private var v_height:int=107;
private var count:Number=0;
public function imgload():void
{
list = new Array();
img = new Array();
}
public function loadImg(str:String):void
{
list = str.split(',');
for(var i:int=0;i<list.length;i++)
{
var loadimg:Loader = new Loader();
loadimg.name = "loadimg"+i;
var url:String = "image/t"+list[i]+".jpg";
loadimg.load(new URLRequest(url));
img.push(loadimg);
}
addListen(img);
}
public function addListen(loadarry:Array):void
{
for(var i:int=0;i<loadarry.length;i++)
{
loadarry[i].contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
}
}
public function onLoadComplete(e:Event):void
{
var l:Loader = e.target.loader;
var n_width:int = l.content.width;
var n_height:int = l.content.height;
var n_num:Number = v_width/v_height;
var t_width:int = n_width;
var t_height:int = n_height;
var rate:int;
var n_state:Boolean = n_width>v_width || n_height>v_height ? true:false;
if(n_state)
{
if(n_width/n_height>n_num)
{
rate = n_width/v_width;
t_width = v_width;
t_height = n_height/rate;
}
else if(n_width/n_height<n_num)
{
rate = n_height/v_height;
t_height = v_height;
t_width = n_width/rate;
}
}
l.content.width=t_width-2;
l.content.height=t_height-2;
l.content.x = 1;
l.content.y = 1;
var boxmc:imgbox = new imgbox();
boxmc.width = t_width;
boxmc.height = t_height;
boxmc.alpha=0;
var mc:MovieClip = new MovieClip();
mc.addChild(boxmc);
mc.width=t_width;
mc.height=t_height;
mc.addChild(l);
mc.x=100;
mc.y=count;
mc.addEventListener(MouseEvent.MOUSE_OVER,function(){boxmc.alpha=100;mc.buttonMode=true;mc.useHandCursor=true;});
mc.addEventListener(MouseEvent.MOUSE_OUT,function(){boxmc.alpha=0;});
addChild(mc);
count = count+t_height;
}
}
}
/***index.fla 第一针.***/
var str:String = "1024,1226,1428,newyearLogo";//图片列表.因为我做的是php+as通信所以这个地方的参数以后是由php来完成的.当 然试验的时候图片的名字为 t1024.jpg,t1226.jpg,t1428.jpg,tnewyearLogo.jpg并放在image文件夹里.
var k:imgload = new imgload();
k.loadImg(str);
addChild(k);
/***库里的文件:***/
mc名-> imgbox [类名:imgbox]
说明:这个imgbox主要是用来做那个鼠标边框的,就是那个蓝色的边框...如果我能做出蓝色+亮色的效果就炫了.
相关文章推荐
- 窗体中有一个图片框,显示一副图片。要求:1)在窗体打开时,动态加载图片;2)设置图片显示模式为根据图片框大小缩放图片;3)图片自己找;4)当鼠标停留在图片框时,显示“**风光”提
- Android中加载的图片自动适应屏幕(新手)
- jq图片预加载+自动等比例缩放插件
- Android代码中动态设置图片的大小(自动缩放),位置
- flash动态加载多张图片
- as3学习笔记3:Loader动态加载图片
- AS3结合XML加载多张图片
- AS3 一个loader加载多张图片
- 图片预加载并且自动等比例缩放的JS插件[转]
- Jquery+ashx当把鼠标放到每篇文章时,自动显示该文章的缩略内容( 图片)的异步加载方法
- Android代码中动态设置图片的大小(自动缩放),位置
- IOS自定义图片浏览器,支持浏览多张图片,点击,双击,两手指缩放操作,并显示加载进度条
- jquery图片预加载+自动等比例缩放插件
- jquery 图片预加载 自动等比例缩放插件
- Axure动态面板:实现图片缩放和进度条加载效果
- 我在使用ng-src时图片加载不出来后,Chrome会自动给img标签增边框,解决办法
- flash加载外部图片等比缩放类(as3)
- 网页随鼠标滚动自动加载 之 网页缩放后失效问题解决方法
- jq图片预加载+自动等比例缩放插件
- WEB页面中如何自动成比例缩放图片,鼠标滚轮缩放