Flash 板


LINE

解决上次的xml读取图片的位置和网址之後, swf已经可以正确地将图片和网址自动更新, 但是这时候又遇到另一个棘手的问题。 原本是用loadMovie来做载入图片的动作, 但是发现这样没办法控制图片的大小, 造成缩图只显示小小一块,常常看不到照片的主角。 查了F1之後,决定改用loadClip来做。 跟据F1上面的解释,onLoadComplete是在「图片载入完成之後」才执行, 所以逻辑上来说,我只要在onLoadComplete里面抓取图片的宽高, 接着和图片的容器大小作等比例缩放,应该就可以完成缩图的动作, 但是实际在做的时候却没这麽顺利。 首先是,我先试着trace载入的图片的大小, 得出来的值却不是图片的大小,而是容器的大小,甚至是0。 再者,我就算写了判断式来进行缩图的动作,也没有进行缩图的动作。 最後解决的方法是在onLoadComplete中, 加入onEnterFrame来不停抓取容器的大小是否改变, 改变之後再依照改变後的宽高来决定怎麽缩图。 到这里算是完全做完了。 但是我有很深的疑问,官方的说法是, onLoadComplete里的函式是在图片载入完成之後才执行, 所以应该是普通时候并不会执行缩图的函式,等到个别的图片载入之後, 再个别做缩图不是吗? 如果要用到onEnterFrame来存取图片的大小那根本没必要用loadClip来做了, 我直接将判断图片大小和缩图的函式写在容器里不就好了吗? 这地方的逻辑我觉得很不通,不知道哪位高手可以帮忙解释一下吗? 谢谢。 顺便附上後来所写的程式: expXML.onLoad = function (success) { if (success){ // trace("EXP Loaded successfully"); // trace(expXML.length); var exp : Array = expXML.firstChild.childNodes; //读取列表内资料 trace(exp[0].firstChild.firstChild.nodeValue); //取出图片路径 trace(exp[0].firstChild.nextSibling.firstChild.nodeValue); //取出网址 for(var j = exp.length + 1; j <= 14; j++){ //隐藏没有图片载入的缩图 tmp = _root["photo" + j + "_mc"]; tmp.enabled = false; var mc_tween:Object = new Tween(tmp, "_alpha", Regular.easeInOut, 100, 0, 0.75, true); }; for(var i = 0; i <= exp.length -1; i++){ //执行载入图片 tmp = _root["photo" + (i + 1) + "_mc"]; tmp.URL = exp[i].firstChild.nextSibling.firstChild.nodeValue; //载入网址 imgLoader.loadClip(exp[i].firstChild.firstChild.nodeValue, tmp.photoLoader_mc.photo_mc); //载入图片 tmp.onRelease = function (){ //缩图被点击时 getURL(this.URL); }; }; } else { loadingImages_mc.gotoAndStop("fail"); }; }; function resizeImg (){ if (this._width < this._parent._parent.photoMask_mc._width && this._height < this._parent._parent.photoMask_mc._height){ //当载入图片宽高皆小於缩图宽高时 this._x = (this._parent._parent.photoMask_mc._width - this._width)/2; this._y = (this._parent._parent.photoMask_mc._height - this._height)/2; var mc_tween:Object = new Tween(this._parent, "_alpha", Regular.easeInOut, 0, 100, 0.75, true); delete this.onEnterFrame; } else if (this._width < this._parent._parent.photoMask_mc._width && this._height > this._parent._parent.photoMask_mc._height){ //当载入图片宽度小於缩图宽度而高度大於缩图高度时 this._x = (this._parent._parent.photoMask_mc._width - this._width)/2; var mc_tween:Object = new Tween(this._parent, "_alpha", Regular.easeInOut, 0, 100, 0.75, true); delete this.onEnterFrame; } else if (this._width > this._parent._parent.photoMask_mc._width && this._height < this._parent._parent.photoMask_mc._height){ //当载入图片高度小於缩图高度而宽度大於缩图宽度时 this._y = (this._parent._parent.photoMask_mc._height - this._height)/2; var mc_tween:Object = new Tween(this._parent, "_alpha", Regular.easeInOut, 0, 100, 0.75, true); delete this.onEnterFrame; } else if(this._width > this._height){ //当宽度大於高度时 this._width = this._width*(this._parent._parent.photoMask_mc._height/this._height); this._height = this._parent._parent.photoMask_mc._height; var mc_tween:Object = new Tween(this._parent, "_alpha", Regular.easeInOut, 0, 100, 0.75, true); delete this.onEnterFrame; } else if(this._height > this._width){ //当高度大於宽度时 this._height = this._height*(this._parent._parent.photoMask_mc._width/this._width); this._width = this._parent._parent.photoMask_mc._width; var mc_tween:Object = new Tween(this._parent, "_alpha", Regular.easeInOut, 0, 100, 0.75, true); delete this.onEnterFrame; } else if (this._width == this._height && (this._width > this._parent._parent.photoMask_mc._width || this._height > this._parent._parent.photoMask_mc._height)){ //当载入图片宽度高度相同且大於缩图宽高时 this._width = this._height = this._parent._parent.photoMask_mc._width; var mc_tween:Object = new Tween(this._parent, "_alpha", Regular.easeInOut, 0, 100, 0.75, true); delete this.onEnterFrame; } else { }; }; /*---------- imgLoader ----------*/ var imgLoader = new MovieClipLoader(); imgLoaderListener = new Object(); imgLoaderListener.onLoadStart = function (target_mc){ }; imgLoaderListener.onLoadProgress = function (target_mc){ }; imgLoaderListener.onLoadComplete = function (target_mc){ target_mc.onEnterFrame = resizeImg; }; imgLoaderListener.onLoadInit = function (target_mc){ }; imgLoaderListener.onLoadError = function (target_mc){ }; imgLoader.addListener(imgLoaderListener); ...糟糕好像太乱了<囧||| -- 某T:我喜欢你>/////< :You gonna try harder...╮(╯_╰)╭ 某T:啥?试着硬一点>///<(羞) :是叫你再努力一点啦<(# ̄皿 ̄)╮☆(__ __||) --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.232.150.160
1F:推 aquarianboy:直接附个fla会不会简单些? :) 01/18 02:43
2F:→ terrylchen:其实贴的那些程式码只是参考而已:),我的问题是关於 01/18 09:52
3F:→ terrylchen:onLoadComplete的观念而已 01/18 09:53







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BabyMother站内搜寻

TOP