喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

[北京]代朋友公司招聘PHP高级程序员多名

上一主题 下一主题
     
标题: [原创] [原创] flash缩放图片  
 
ydl0025
新手上路
Rank: 1


UID 105120
精华 0
积分 49
帖子 78
金钱 49 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-12-29
来自 北京
状态 离线
[原创] flash缩放图片

今晚用flash做了一个图片缩放功能,把它拿上来供以后参考!



步骤1:制作四个按钮,分别是刷新按钮,放大按钮,缩小按钮,原始尺寸按钮,排列在场景左上角;



步骤2:创建两个空影片,放到场景中,其中一个命名为pic(用来加载图片),另一个命名为trigger(用来触发为特定影片剪辑实例定义的动作);



步骤3:在场景第一帧添加如下脚本:



//显示图片
function picShow() {
//如果场景存在pic影片
with (_root.pic) {
  //取得加载图片大小
  _root.picWidth = _width;
  _root.picHeight = _height;
}


//调用设置图片大小的方法
_root.picFitToStage();
//调用设置图片位置的方法
_root.picMoveToCenter();
//创建对象
stageListener = new Object();


//当调整swf大小时,重新定位图片大小和位置
stageListener.onResize = function() {
  var _l1 = _root;
  if (_l1.pic) {
   _l1.picFitToStage();
   _l1.picMoveToCenter();
  }
};
Stage.addListener(stageListener);
}


//设置图片大小
function picFitToStage() {
with (_root.pic) {
  _width = _root.picWidth;
  _height = _root.picHeight;
  //取得场景宽度
  sWidth = Stage.width;
  //设置导航条宽度为场景宽度
  _root.hom._width = sWidth;
  //取得场景高度(去掉导航条高度)
  sHeight = Stage.height-menuHeight;
  //使图片适应场景
  if (_width>sWidth || _height>sHeight) {
   if (_width/sWidth>=_height/sHeight) {
    _height = _height/_width*sWidth;
    _width = sWidth;
   } else {
    _width = _width/_height*sHeight;
    _height = sHeight;
   }
  }
}
}


//刷新
function picRefresh() {
var _l1 = _root;
_l1.picFitToStage();
_l1.picMoveToCenter();
}


function picZoom(ratio) {
with (_root.pic) {
  _x = _x-_width*(ratio/2-0.500000);
  _y = _y-_height*(ratio/2-0.500000);
  _width = _width*ratio;
  _height = _height*ratio;
}
}


function picActualSize() {
with (_root.pic) {
  _x = _x+(_width-_root.picWidth)/2;
  _y = _y+(_height-_root.picHeight)/2;
  _width = _root.picWidth;
  _height = _root.picHeight;
}
}


//设置图片位置
function picMoveToCenter() {
var _l1 = _root;
_l1.pic._x = (Stage.width-_l1.pic._width)/2;
_l1.pic._y = (Stage.height-_l1.menuHeight-_l1.pic._height)/2+_l1.menuHeight;
}


//设置或检索用于影片剪辑的呈现品质
_quality = "BEST";
//指示 SWF 文件在 Flash Player 内当前的缩放比例
Stage.scaleMode = "noScale";
//指示 SWF 文件在播放器或浏览器中当前的对齐方式
Stage.align = "tl";
Stage.showMenu = false;
//图片链接地址
var picURL;
picURL = "1.jpg";
//picURL = decode(picURL, "3irjklsd8432uisdklvr892348");
//图片宽度
var picWidth = 0;
//图片高度
var picHeight = 0;
//导航条高度
var menuHeight = 30;
var isZooming = false;
//缩放系数
var picZoomRatio = 1;
var lastClickTime = 0;
var curToolTip = "";
//加载图片到影片pic
_root.pic.loadMovie("1.jpg");



步骤4:在各个按钮上添加脚本

1)刷新按钮添加如下脚本:

on (release) {
_root.picRefresh();
}


on (rollOver) {
_root.curToolTip = "刷新";
}


2)放大按钮添加如下脚本:

on (press) {
_root.isZooming = true;
_root.picZoomRatio = 1.100000;
}


on (release) {
_root.isZooming = false;
}


on (releaseOutside) {
//在鼠标指针位于按钮内部的情况下按下按钮,然后将鼠标指针移到该按钮外部并释放鼠标按钮
_root.isZooming = false;
}


on (rollOver) {
_root.curToolTip = "放大";
}


3)缩小按钮添加如下脚本:

on (press) {
_root.isZooming = true;
_root.picZoomRatio = 0.909091;
}


on (release) {
_root.isZooming = false;
}


on (releaseOutside) {
_root.isZooming = false;
}


on (rollOver) {
_root.curToolTip = "缩小";
}


4)原始大小按钮添加如下脚本:

on (release) {
picActualSize();
}


on (rollOver) {
_root.curToolTip = "原始尺寸";
}


步骤5:在swf同目录存放一张jpg图片,命名为1.jpg,现在就可以随意处置这张图片了!

好了,就这么多,下次再继续......




没有什么事是做不到的,关键是你有没有去做
2007-12-29 01:26 PM#1
查看资料  访问主页  Blog  发短消息  QQ  顶部
 
fimdy
乞丐




UID 105140
精华 0
积分 -1
帖子 16
金钱 -1 喜悦币
威望 0
人脉 0
阅读权限 1
注册 2007-12-29
状态 离线
[推荐阅读] 网易的评论好牛:《色,戒》激情场面真假难辨 引发网友热议查看原文
多谢楼主分享,嘿嘿
2007-12-29 09:23 PM#2
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.027442 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP