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燈, 水草

請輸入看板名稱,例如:e-shopping站內搜尋

TOP