|
|
|
|
解决yamago上传组件-2004版 |
| 作者:佚名 来源:不详 更新:2007-1-13 20:42:52 错误报告 我要投稿 |
yamago 是个上传组件, 但只开发到MX的版本.... 是个很好用的组件, 如果自己写过组件的朋友一定有碰到在submit()的时候无法把form提交的问题吧... 为了方便在这里提供了 yamago 组件为何在2004无法使用的原因 首先没用过的朋友可以从这里下载 http://sourceforge.net/projects/yamzbrowser/ 这里是实例 http://www.yamago.net/components/ 那么先安装了之后, 把组件拖到场景上直接测试, 会发现按钮会一直闪 主要原因是在2004版本当中, 组件中并没任何代码... 所以我们就要自己手动加上, 步骤如下 步骤 1: 编辑此组件, 如图 :

步骤 2: 因为这个是以MX版本编写的组件, 所以当中的代码是以#initclip开始和#endinitclip结束, 所以在第二图层空白的帧上加入此代码
#initclip if (Yamzbrowser == undefined) { _global.Yamzbrowser = function() { this.loaded = undefined; this.status = 0; this.lcObj = this._name+getTimer(); this.browseLC = new LocalConnection(); this.browseLC.parent = this; this.browseLC.getFile = this.getFile; this.browseLC.getUpload = this.getUpload; this.btnBrowse.stop(); this.btnUpload.stop(); if (MMSave == undefined) { if (Yamzbrowser.iemac) { this.btnBrowse.onRelease = this.release; this.btnBrowse.onRollOver = nextFrame; this.btnBrowse.onRollOut = prevFrame; } else { this.btnBrowse.onRollOver = this.rollOver; } this.btnUpload.onRelease = this.upload; this.btnUpload.onRollOver = nextFrame; this.btnUpload.onRollOut = prevFrame; this.btnUpload.enabled = false; } else { this.btnBrowse.onRollOver = (this.btnUpload.onRollOver=nextFrame); this.btnBrowse.onRollOut = (this.btnUpload.onRollOut=prevFrame); } Yamzbrowser.list.push(this); }; Yamzbrowser.prototype = new MovieClip(); Object.registerClass("idYamzbrowser", Yamzbrowser); Yamzbrowser.iemac = _root.__yamzbrowser == "Microsoft Internet Explorer"; delete _root.__yamzbrowser; Yamzbrowser.stageHeight = Stage.height; Yamzbrowser.stageWidth = Stage.width; Yamzbrowser.list = []; Yamzbrowser.prototype.getFile = function(pData) { var lParent = this.parent; this.close(); lParent.target = pData; lParent.txtBrowse.hscroll = lParent.txtBrowse.maxhscroll; lParent.btnUpload.enabled = true; for (var z in Yamzbrowser.list) { var lRef = Yamzbrowser.list[z]; if (lRef != this.parent) { lRef.browseLC.close(); lRef.btnUpload.prevFrame(); lRef.btnUpload.enabled = false; lRef.txtBrowse.text = ""; } } }; Yamzbrowser.prototype.getUpload = function(pStatus, pFile, pParam) { var lParent = this.parent; this.close(); lParent.btnUpload.prevFrame(); lParent.btnBrowse.enabled = true; lParent.loaded = true; lParent.status = Number(pStatus); lParent.txtBrowse.text = ""; lParent._enabledBrowse(true); lParent.onUpload(pFile, unescape(pParam)); }; Yamzbrowser.prototype.upload = function() { var lParent = this._parent; this.enabled = false; lParent.btnBrowse.enabled = false; lParent.browseLC.connect(lParent.lcObj); getURL(((((("javascript :upLoadFile(\''''''''"+lParent.lcObj)+"\'''''''',\''''''''")+lParent.script)+"\'''''''',\''''''''")+escape(lParent.data.split("\''''''''").join("\\\''''''''")))+"\'''''''');"); lParent.loaded = false; lParent._enabledBrowse(false); lParent.startUpload(); }; Yamzbrowser.prototype.rollOver = function() { var lParent = this._parent; lParent.browseLC.connect(lParent.lcObj); this.onEnterFrame = lParent.rollOut; this.onRollOver = null; var lPos = this.getBounds(); var lMin = {x:lPos.xmin, y:lPos.ymin}; var lMax = {x:lPos.xmax, y:lPos.ymax}; var lMouse = {x:this._xmouse, y:this._ymouse}; this.localToGlobal(lMin); this.localToGlobal(lMax); this.localToGlobal(lMouse); if (Stage.scaleMode == "noScale") { var lHeight = Yamzbrowser.stageHeight; var lWidth = Yamzbrowser.stageWidth; } else { var lHeight = Stage.height; var lWidth = Stage.width; } getURL(((((((((((((((((((((((("javascript :browseEnabled(\''''''''"+lParent.lcObj)+"\'''''''',\''''''''")+Stage.scaleMode)+"\'''''''',\''''''''")+Stage.align)+"\'''''''',")+lWidth)+",")+lHeight)+",")+lMin.x)+",")+lMin.y)+",")+lMax.x)+",")+lMax.y)+",")+lMouse.x)+",")+lMouse.y)+",")+this.useHandCursor)+");"); this.nextFrame(); }; Yamzbrowser.prototype.rollOut = function() { var lParent = this._parent; if (!this.hitTest(_root._xmouse, _root._ymouse, true)) { lParent.status = 0; this.onRollOver = lParent.rollOver; delete this.onEnterFrame; this.prevFrame(); } }; Yamzbrowser.prototype.release = function() { var lParent = this._parent; lParent.browseLC.connect(lParent.lcObj); getURL(("javascript :clickIEMac(\''''''''"+lParent.lcObj)+"\'''''''');"); }; Yamzbrowser.prototype._enabledBrowse = function(pBool) { for (var z in Yamzbrowser.list) { Yamzbrowser.list[z].btnBrowse.enabled = pBool; } }; Yamzbrowser.prototype.onUpload = function(pFile, pParam) { trace("file uploaded: "+pFile); trace("param: "+pParam); }; } #endinitclip
步骤 3: 发布的时候设定Flash以 Flash Player 6 格式发布, 当然写过组件的朋友也很清楚, 也知道怎样修改一次, 以后就不用修改了吧... 或者有兴趣的朋友可以写成 2004 的组件格式 :) 步骤 4: 在html的部分依照yamago提供的例子把所需的javascript代码加入就可以了 :), 这里把代码各别以颜色分出来了...
<HTML> <HEAD> <TITLE>YamzBrowser - Flash Upload Component</TITLE> <meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> <style type="text/css"> <!-- .invisible {-moz-opacity: 0; filter: alpha(opacity=0);} .invisible2 {-moz-opacity: 0%; filter: alpha(opacity=0);} --> </style> <script> // YamzBrowser 1.2 beta window.onerror=function(pMes,pUrl,pLine) { return true; } var _xmouse, _ymouse, box={}, lcFile=""; lcTemp=""; function init() { createEmptyWindow(); b=document.getElementById("browseLayer").style; c=document.getElementById("browseLayer").className;
f=document.getElementById("flashLayer"); w=document.getElementById("file"); d=document.flashLayer; lWin=(window.navigator.appName=="Microsoft Internet Explorer"); var lVendor=(window.navigator.vendor==""); var lUser=window.navigator.userAgent; var lPos=lUser.indexOf("rv:"); var lOldMoz = (lPos!=-1 && parseFloat(lUser.substr(lPos+3,3))<1.4);
if (!lWin && lVendor && lOldMoz) { document.getElementById("browseLayer").className="invisible2"; document.getElementById("ifr").className="invisible2"; }
if (window.navigator.platform!="MacPPC") { if (lWin) w.onchange=browse; else w.onclick=browse; w.onfocus=lcChoice; } else { w.onclick = lWin ? browseIE : browse; w.onfocus= lWin ? null : lcChoice; }
window.document.upload.reset(); } function mousePos(e) { if (e) { _xmouse=e.pageX; _ymouse=e.pageY; } else { _xmouse=event.x; _ymouse=event.y; }
if (lWin) { var mouseX=_xmouse+document.body.scrollLeft; var mouseY=_ymouse+document.body.scrollTop; } else { var mouseX=_xmouse; var mouseY=_ymouse; }
if (mouseX>box.xmin && mouseX<box.xmax && mouseY>box.ymin && mouseY<box.ymax) { b.left=mouseX-70; b.top=mouseY-10; } else browseDisabled(); } function browseEnabled(pLC,pMode,pAlign,pXflash,pYflash,pXmin,pYmin,pXmax,pYmax,pXm,pYm,pCursor) { switch (pMode) { case "showAll": lScaleX=lScaleY=Math.min(d.offsetWidth/pXflash,d.offsetHeight/pYflash); var lX=(d.offsetWidth-pXflash*lScaleX)/2; var lY=(d.offsetHeight-pYflash*lScaleY)/2; break; case "noScale": lScaleX=lScaleY=1; if (pAlign.indexOf("T")!=-1) lY=0; else if (pAlign.indexOf("B")!=-1) lY=(d.offsetHeight-pYflash); else lY=(d.offsetHeight-pYflash)/2; if (pAlign.indexOf("L")!=-1) lX=0; else if (pAlign.indexOf("R")!=-1) lX=(d.offsetWidth-pXflash); else lX=(d.offsetWidth-pXflash)/2; break; case "exactFit": var lScaleX=d.offsetWidth/pXflash; var lScaleY=d.offsetHeight/pYflash; var lX=0,lY=0; break; case "noBorder": lScaleX=lScaleY=Math.max(d.offsetWidth/pXflash,d.offsetHeight/pYflash); var lX=(d.offsetWidth-pXflash*lScaleX)/2; var lY=(d.offsetHeight-pYflash*lScaleY)/2; break; } w.style.cursor=pCursor ? "hand" : "default"; b.visibility=''''''''visible''''''''; lcTemp=pLC;
var lLeft= (!lWin && f.style.left!="") ? parseInt(f.style.left) : 0; var lTop= (!lWin && f.style.top!="") ? parseInt(f.style.top) : 0;
box.xmin=lLeft+d.offsetLeft+pXmin*lScaleX-2+lX; box.ymin=lTop+d.offsetTop+pYmin*lScaleY-2+lY; box.xmax=lLeft+d.offsetLeft+pXmax*lScaleX+4+lX; box.ymax=lTop+d.offsetTop+pYmax*lScaleY+4+lY; b.left=d.offsetLeft+pXm*lScaleX+lX-70; b.top=d.offsetTop+pYm*lScaleY+lY-10; document.onmousemove=mousePos; } function lcChoice () { lcFile=lcTemp; } function clickIEMac(pLC) { lcFile=pLC; w.click(); } function browseDisabled() { b.visibility=''''''''hidden''''''''; document.onmousemove=null; } function browse() { if (w.value!="") { wp= window.open("","pop"); setTimeout("createWindow(''''''''getFile'''''''',lcFile,w.value,'''''''''''''''')",100); } browseDisabled(); } function browseIE() { setTimeout("browse()",200); } function upLoadFile(pLC,pScript,pData) { window.alert(pLC+", "+pScript+", "+pData); window.document.upload.action=pScript+"?browseLC="+pLC+"&dataLC="+pData; createEmptyWindow(); window.document.upload.submit(); } function upLoadEnd (pLC,pStatus,pFile,pData) { wp= window.open("","pop"); setTimeout("onUpLoadEnd(''''''''"+pLC+"'''''''',"+pStatus+",''''''''"+pFile+"'''''''',''''''''"+pData+"'''''''')",100); } function onUpLoadEnd(pLC,pStatus,pFile,pData) { createWindow("getUpload",pLC,pStatus,pFile,pData); if (!(lWin && window.navigator.platform!="MacPPC")) window.document.upload.reset(); } function createEmptyWindow () { wp= window.open("","pop"); wp.document.open(); wp.document.write(''''''''<HTML><BODY bgcolor="#999999" scroll="no"></BODY></HTML>''''''''); wp.document.close(); } function createWindow (pMeth,pBrowse,pTxt,pFile,pData) { wp.document.open(); if (typeof pData=="undefined") pData=""; var lTemp=''''''''<HTML><BODY scroll="no" bgcolor="#999999"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="1" HEIGHT="1" id="browse">''''''''; lTemp+= ''''''''<PARAM NAME=movie VALUE="browse.swf">''''''''; lTemp+= ''''''''<PARAM NAME=FlashVars VALUE="methLC=''''''''+pMeth+''''''''&browseLC=''''''''+pBrowse+''''''''&txtLC=''''''''+pTxt+''''''''&fileLC=''''''''+pFile+''''''''¶mLC=''''''''+pData+''''''''">''''''''; lTemp+= ''''''''<EMBED src="browse.swf" flashVars="methLC=''''''''+pMeth+''''''''&browseLC=''''''''+pBrowse+''''''''&txtLC=''''''''+pTxt+''''''''&fileLC=''''''''+pFile+''''''''¶mLC=''''''''+pData+''''''''" WIDTH="1" HEIGHT="1" NAME="browse" ''''''''; wp.document.write(lTemp+ ''''''''TYPE="application/x-shockwave-flash"></EMBED></OBJECT></BODY></HTML>''''''''); wp.document.close(); } </script> <TITLE>browser</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD> <BODY bgcolor="#FFFFFF" onload="init();" > <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="600" HEIGHT="400" id="flashLayer" ALIGN="" style="position:absolute; left: 100px; top: 50px; z-index:10;"> <PARAM NAME=movie VALUE="example.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <PARAM NAME=wmode VALUE="Opaque"> <script> document.write(''''''''<EMBED src="example.swf" quality=high bgcolor=#FFFFFF src="example.swf" quality=high bgcolor=#999999 wmode="Opaque" flashvars="__yamzbrowser=''''''''+window.navigator.appName+''''''''" WIDTH="600" HEIGHT="400" NAME="flashLayer" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>''''''''); </script> </OBJECT> <div class="invisible" id="browseLayer" style="position:absolute; width:100px; height:10px; z-index:15; left: 0px; top: 0px; visibility:hidden;"> <form name="upload" method="post" enctype="multipart/form-data" target="pop"> <input id="file" type="file" name="fichier" size="1"> </form> </div> <IFRAME class="invisible" id="ifr" src="" name="pop" width=200 height=50 frameborder="0" scroll="no"></IFRAME> </BODY> </HTML> 步骤 5: 后台的脚本我也分别提供给大家... 分别为asp, php和cfm格式, 以下都是允许的格式为jpeg/jpg, 最大2MB
| ASP 后台 |
<% On Error Resume Next response.expires = -1 response.AddHeader "Pragma", "no-cache" response.AddHeader "cache-control", "no-store" test = Request("browseLC") test2 = Request("dataLC") Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload") mySmartUpload.AllowedFilesList = "jpg,jpeg" mySmartUpload.MaxFileSize = 20000 mySmartUpload.Upload For Each file In mySmartUpload.files If Not file.IsMissing Then fichier_name=file.FileName file.SaveAs(Server.MapPath("img/" & fichier_name)) End If Next status=0 If Err = -2147220399 Then status=-2 else If Err <> 0 Then status=-1 end if end if Response.Write("<HTML><BODY><script>window.top.upLoadEnd(''''''''" & test & "'''''''',"& status &",''''''''" & fichier_name &"'''''''',''''''''" & test2 & "'''''''')</script></HTML>") %> |
| ColdFusion 后台 |
<cfheader name="Expires" value="#Now()#"> <cfset max_size=20000> <cfset path="E:\home\mediamo\public_html\labo\img\"> <cfset nonjpeg=1> <cffile action="upload" filefield="fichier" destination="#path#" nameconflict="overwrite"> <cfset imgname=#File.ClientFile#> <cfif (#file.FileSize# GT #max_size#) OR (#file.FileSize# EQ 0)> <cfset error=-2> <cfelseif (#file.ClientFileExt# EQ "jpg") OR (#file.ClientFileExt# EQ "jpeg")> <cfset nonjpeg=0> <cfelse> <cfset status=0> </cfif> <cfif IsDefined(''''''''error'''''''') AND #error# EQ -2> <cfset status=-2> <cffile action="delete" file="#path##imgname#"> <cfelseif IsDefined(''''''''nonjpeg'''''''') AND #nonjpeg# EQ 1> <cfset status=-1> <cffile action="delete" file="#path##imgname#"> <cfelse> <cfset status=0> </cfif> <cfoutput><HTML><BODY><script>window.top.upLoadEnd(''''''''#browseLC#'''''''',#status#,''''''''#imgname#'''''''',''''''''#dataLC#'''''''')</script></HTML></cfoutput> |
| PHP 后台 |
<?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Pragma: no-cache"); $max_size = 20000; // 文件大小 $max_width = 2000; $max_height = 2000; $dirname = ''''''''img''''''''; // 储存图片路径 if (isset($fichier)) $tab = GetImageSize($fichier); if ($fichier_size > $max_size || $fichier_size == 0) $status=-2; else if (!$fichier || $fichier == "none") $status=-1; else if (strpos($fichier_name,"\\") || strpos($fichier_name, "/")) $status=-1; else if (!stristr($fichier_name, ".jpg")) $status=-1; else if (!$tab[0]) $status=-3; else if (!stristr($fichier_type, "jpeg")) $status=-1; else if ($tab[0] > $max_width) $status=-4; else if($tab[1] > $max_height) $status=-5; else { copy($fichier, $dirname."/".$fichier_name); $status=0; } echo "<HTML><BODY><script>window.top.upLoadEnd(''''''''$browseLC'''''''',$status,''''''''$fichier_name'''''''',''''''''".urlencode("%+datas from server: $dataLC")."'''''''')</script></HTML>"; ?> |
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
|
|
|
|