[AS3]as3实现图片缩放效果源代码实例
[AS3]as3实现图片缩放效果源代码实例
[AS3]as3实现图片缩放效果源代码实例
- package
- {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.events.Event;
- public class Main extends Sprite
- {
- public function Main()
- {
- initPic();
- }
- //3行4列
- var i_max:Number = 3;
- var j_max:Number = 4;
- //初始化图片
- private function initPic():void
- {
- //显示存在原件中的12个图片
- for (var i:Number=0; i<i_max; i++)
- {
- for (var j:Number=0; j<j_max; j++)
- {
- var mc:Mc=new Mc();
- mc.x = j * stage.stageWidth / j_max;
- mc.y = i * stage.stageHeight / i_max;
- mc.width = stage.stageWidth / j_max;
- mc.height = stage.stageHeight / i_max;
- mc["sx"] = mc.x;//小图时的x轴坐标
- mc["sy"] = mc.y;//小图时的y轴坐标
- mc["sw"] = mc.width;//小图片的宽
- mc["sh"] = mc.height;//小图片的高
- mc["isSmall"] = true;//存放图图片是否是小图
- mc.gotoAndStop(i*j_max+j+1);
- mc.addEventListener(MouseEvent.CLICK, mouseClickHandler);
- stage.addChild(mc);
- }
- }
- }
- //CuPlayer.com单击图片
- private function mouseClickHandler(event:MouseEvent):void
- {
- var mc:Mc = event.target as Mc;
- //将被单击图片至于最上
- stage.setChildIndex(mc,stage.numChildren-1);
- //单击图片,如果图片是小图就放大,如果已经放大了就还原;
- if (mc["isSmall"])
- {
- mc.addEventListener(Event.ENTER_FRAME, zoomInPic);
- mc.removeEventListener(Event.ENTER_FRAME,zoomOutPic);
- }
- else
- {
- mc.addEventListener(Event.ENTER_FRAME, zoomOutPic);
- mc.removeEventListener(Event.ENTER_FRAME,zoomInPic);
- }
- mc["isSmall"] = ! mc["isSmall"];
- }
- //CuPlayer.com放大图片
- private function zoomInPic(event:Event):void
- {
- //CuPlayer.com将图片改为x=0,y=0,width=stage.stageWidth,height=stage.stageHeight
- var mc:Mc = event.target as Mc;
- mc.x += (0 - mc.x) / 5;
- mc.y += (0 - mc.y) / 5;
- mc.width+=(stage.stageWidth-mc.width)/5;
- mc.height+=(stage.stageHeight-mc.height)/5;
- }
- //CuPlayer.com缩小图片
- private function zoomOutPic(event:Event):void
- {
- //CuPlayer.com将图片还原
- var mc:Mc = event.target as Mc;
- mc.x += (mc["sx"] - mc.x) / 5;
- mc.y += (mc["sy"] - mc.y) / 5;
- mc.width+=(mc["sw"]-mc.width)/5;
- mc.height+=(mc["sh"]-mc.height)/5;
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...