var SWFDesignText; function string() { var list = new Array(); for(var i=0; i<arguments.length; i++) list.push(arguments[i]) return list.join(""); } if (SWFDesignText == undefined) { SWFDesignText = function (settings) { this.initSWFDesignText(settings); }; } SWFDesignText.prototype.initSWFDesignText = function (settings) { try { this.settings = settings; this.movieName = "SWFDesignText"; this.movieElement = null; SWFDesignText.instances[this.movieName] = this; this.initSettings(); this.loadFlash(); } catch (ex) { delete SWFDesignText.instances[this.movieName]; throw ex; } }; SWFDesignText.instances = {}; SWFDesignText.version = "2.0.0 2009-07-1"; SWFDesignText.WINDOW_MODE = { WINDOW : "window", TRANSPARENT : "transparent", OPAQUE : "opaque" }; SWFDesignText.prototype.completeURL = function(url) { if (typeof(url) != "string" || url.match(/^http?:/i) || url.match(/^///)) { return url; } var indexSlash = window.location.pathname.lastIndexOf("/"); if (indexSlash <= 0) { path = "/"; } else { path = window.location.pathname.substr(0, indexSlash) + "/"; } return path + url; }; //初始化設置 SWFDesignText.prototype.initSettings = function () { this.ensureDefault = function (settingName, defaultValue) { this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName]; }; this.ensureDefault("FlashUrl", "SWFDesignText.swf"); this.ensureDefault("LabelInfo", ""); this.ensureDefault("ImageUrl",""); this.ensureDefault("PlaceHolderID", ""); this.ensureDefault("PlaceHolder", null); this.ensureDefault("TextEditorID", ""); this.ensureDefault("TextEditor", null); this.ensureDefault("SceneWidth", 300); this.ensureDefault("SceneHeight", 300); this.ensureDefault("WindowMode", SWFDesignText.WINDOW_MODE.WINDOW); this.settings.ImageUrl = this.completeURL(this.settings.ImageUrl); delete this.ensureDefault; }; //加載Flash SWFDesignText.prototype.loadFlash = function () { var targetElement, tempParent; if (document.getElementById(this.movieName) !== null) { throw "ID " + this.movieName + " is already in use. The Flash Object could not be added"; } targetElement = document.getElementById(this.settings.PlaceHolderID) || this.settings.PlaceHolder; this.TextEditor = document.getElementById(this.settings.TextEditorID) || this.settings.TextEditor; if (targetElement == undefined) { throw "Could not find the placeholder element: " + this.settings.PlaceHolderID; } tempParent = document.createElement("div"); tempParent.innerHTML = this.getFlashHTML(); targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement); if (window[this.movieName] == undefined) { window[this.movieName] = this.getMovieElement(); } }; //生成加載Flash的Html SWFDesignText.prototype.getFlashHTML = function () { return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.FlashUrl, '" width="', this.settings.SceneWidth, '" height="', this.settings.SceneHeight, '" class="SWFDesignText">', '<param name="wmode" value="', this.settings.WindowMode, '" />', '<param name="movie" value="', this.settings.FlashUrl, '" />', '<param name="quality" value="high" />', '<param name="menu" value="false" />', '<param name="allowScriptAccess" value="always" />', '<param name="flashvars" value="' + this.getFlashVars() + '" />', '</object>'].join(""); }; //取Flash參數 SWFDesignText.prototype.getFlashVars = function () { return ["movieName=", encodeURIComponent(this.movieName), "&LabelInfo=", encodeURIComponent(this.settings.LabelInfo), "&ImageUrl=",encodeURIComponent(this.settings.ImageUrl), "&SceneWidth=",encodeURIComponent(this.settings.SceneWidth), "&SceneHeight=",encodeURIComponent(this.settings.SceneHeight) ].join(""); }; //用於初始化原來有的label記錄 SWFDesignText.prototype.setLabel = function(labsinfo) { if(labsinfo != null) //原來有的標籤記錄來至數據庫插入到flex中 this.callFlash("setLabel",[labsinfo]); }; //取得添加label對象 SWFDesignText.prototype.addControl = function() { this.callFlash("addControl"); }; //刪除標籤 SWFDesignText.prototype.deleteControl = function() { this.callFlash("deleteControl"); }; //設置flash圖片大小 SWFDesignText.prototype.setImageSize = function(width,height) { if (width != null && height != null) this.callFlash("setImageSize",[width,height]); }; //改變字體顏色 SWFDesignText.prototype.setColor = function(colValue) { if (colValue != null) this.callFlash("setColor",[colValue]); }; //重新設置flash中label的文本 SWFDesignText.prototype.setText = function(content) { if (content != null) this.callFlash("setText",[content.replace(//r/n/gi, " ")]); }; //設置flash背景圖片 SWFDesignText.prototype.setBackgroundImage = function(url) { if (url != null) //var imageurl = "../images/a368344s.jpg"; this.callFlash("setBackgroundImage",[url]); }; //設置文本字體大小 SWFDesignText.prototype.setFontSize = function(sizeValue){ this.callFlash("setFontSize",[sizeValue]); }; //設置文本字體粗體 SWFDesignText.prototype.setFontBold = function(){ this.callFlash("setFontBold"); }; //設置文本字體斜體 SWFDesignText.prototype.setFontItalic = function(){ this.callFlash("setFontItalic"); }; //設置文本字體下畫線 SWFDesignText.prototype.setFontUnderline = function(){ this.callFlash("setFontUnderline"); }; //設置文本對齊 SWFDesignText.prototype.setAlignLeft = function(){ this.callFlash("setAlignLeft"); }; //設置文本對齊 SWFDesignText.prototype.setAlignCenter = function(){ this.callFlash("setAlignCenter"); }; //設置文本對齊 SWFDesignText.prototype.setAlignRight = function(){ this.callFlash("setAlignRight"); }; //設置label中文本的字體 SWFDesignText.prototype.setFontFamily = function(fontFamily) { this.callFlash("setFontFamily",[fontFamily]); }; //此方法將flex的label中的內容回綁到編輯文本 SWFDesignText.prototype.callBackInfo = function (txt,font,size) { if(txt!= null) this.TextEditor.value = txt.replace(/<//p>/gi,"/r/n").replace(/<(.*?)>/gi,""); }; //獲取序列化信息 SWFDesignText.prototype.getInfo = function() { return this.callFlash("getInfo"); }; //獲取對象 SWFDesignText.prototype.getMovieElement = function () { if (this.movieElement == undefined) { this.movieElement = document.getElementById(this.movieName); } if (this.movieElement === null) { throw "Could not find Flash element"; } return this.movieElement; }; //調用Flash的AS中的方法 SWFDesignText.prototype.callFlash = function (functionName, args) { args = args || []; var movieElement = this.getMovieElement(); var returnValue, returnString; try { returnString = movieElement.CallFunction(string('<invoke name = "', functionName, '" returntype = "javascript">', __flash__argumentsToXML(args, 0), '</invoke>')); returnValue = eval(returnString); } catch (Exception) { throw string("Call to ", functionName, " failed"); } if (returnValue != undefined && typeof returnValue.post == "object") { returnValue = this.unescapeFilePostParams(returnValue); } return returnValue; };