Bonjour,
Je ne m'y connais pas assez en AS pour comprendre d'où vient le pb...
Voici le code que je mettais pour charger un texte dynamique (avec couleur, soulignement, etc...) dans flash mx :
#initclip 1
if (LoadTextClass == undefined) {
LoadTextClass = function () {
this._visible=false;
this.init();
};
LoadTextClass.prototype = new MovieClip();
Object.registerClass("LoadText", LoadTextClass);
LoadTextClass.prototype.init = function() {
this.defineProperties();
this.loadedz=false;
if (this.usecodepage==undefined) this.usecodepage=true;
if (this.enablehtml==undefined) this.enablehtml=true;
if (this.enabletracing==undefined) this.enabletracing=true;
if (this._targetInstanceName!=undefined) {
this.setTarget(this._targetInstanceName)
this.originalText = this.targetInstance.text;
if (this.targetInstance!=undefined) this.loadText(this.textfile,this.targetInstance);
}
};
LoadTextClass.prototype.defineProperties = function() {
this.addProperty("_text", this.getTextFile, this.setTextFile);
this.addProperty("_targetField", this.getTarget, this.setTarget);
this.addProperty("_html", this.getHtml, this.setHtml);
this.addProperty("_accents", this.getAccents, this.setAccents);
this.addProperty("_waitingText", this.getWaitingText, this.setWaitingText);
this.addProperty("_tracing", this.getTracing, this.setTracing);
this.addProperty("_loaded",this.getLoaded, null);
this.addProperty("_targetVar",this.getTargetVar, this.setTargetVar);
this.addProperty("_callback",this.getCallback, this.setCallback);
this.addProperty("_allowedDomain",this.getAllowedDomain, this.setAllowedDomain);
this.addProperty("_caching",this.getCaching, this.getCaching);
this.addProperty("_bytesLoaded",this.getBytesLoaded, null);
this.addProperty("_bytesTotal",this.getBytesTotal, null);
}
LoadTextClass.prototype.getTextFile = function() {
return this.textfile;
}
LoadTextClass.prototype.setTextFile = function(urlz) {
this.textfile = urlz
return urlz;
}
LoadTextClass.prototype.getTarget = function() {
return this.targetInstance;
}
LoadTextClass.prototype.setTarget = function(tf) {
this.targetInstance = (this._parent[tf] instanceof TextField) ? this._parent[tf] : eval(tf);
return tf;
}
LoadTextClass.prototype.getHtml = function() {
return (this.enablehtml==true) ? true : false;
}
LoadTextClass.prototype.setHtml = function(bool) {
this.enablehtml=bool;
return (this.enablehtml==bool) ? true : false;
}
LoadTextClass.prototype.getAccents = function() {
return (this.usecodepage==true) ? true : false;
}
LoadTextClass.prototype.setAccents = function(bool) {
this.usecodepage=bool;
return (this.usecodepage==bool) ? true : false;
}
LoadTextClass.prototype.getWaitingText = function() {
return this.waitingtext;
}
LoadTextClass.prototype.setWaitingText = function(bla) {
this.waitingtext=bla;
return bla;
}
LoadTextClass.prototype.getTracing = function() {
return (this.enabletracing==true) ? true : false;
}
LoadTextClass.prototype.setTracing = function(bool) {
this.enabletracing=bool;
return (this.enabletracing==bool) ? true : false;
}
LoadTextClass.prototype.getLoaded = function() {
return this.loadedz;
}
LoadTextClass.prototype.getTargetVar = function() {
return this.targetVar;
}
LoadTextClass.prototype.setTargetVar = function(targetz) {
this.targetVar = targetz
return targetz;
}
LoadTextClass.prototype.getCallback = function() {
return this.callback;
}
LoadTextClass.prototype.setCallback = function(callback) {
this.callback = callback
return callback;
}
LoadTextClass.prototype.getAllowedDomain = function() {
return this.secdomain;
}
LoadTextClass.prototype.setAllowedDomain = function(secdomain) {
this.secdomain = secdomain;
return secdomain;
}
LoadTextClass.prototype.getCaching = function() {
return (this.caching==true) ? true : false;
}
LoadTextClass.prototype.setCaching = function(bool) {
this.caching=bool;
return (this.caching==bool) ? true : false;
}
LoadTextClass.prototype.getBytesLoaded = function() {
if (this.loadTextRaw) return this.loadTextRaw.getBytesLoaded();
//else return 0;
}
LoadTextClass.prototype.getBytesTotal = function() {
if (this.loadTextRaw) return this.loadTextRaw.getBytesTotal();
//else return 0;
}
String.prototype.LoadTextReplace = function(strng, toReplace) {
var temparray = this.split(strng);
return temparray.join(toReplace);
};
LoadTextClass.prototype.loadText = function(textfile,targetz) {
if (textfile != undefined) this.textfile=textfile;
if (targetz.length>0) {
this.setTarget(targetz)
}
System.useCodepage = (this.usecodepage==true) ? true : false;
if (System.capabilities.manufacturer=="Macintosh") System.useCodePage=false; // mac bug patch
if (this.secdomain!=undefined && this.secdomain!="") {
System.security.allowDomain(this.secdomain);
if (this.enabletracing) trace ("--- LoadText secured domain: "+this.secdomain);
}
if (this.targetInstance != undefined) {
if (this.targetInstance instanceof TextField) {
if (this.targetInstance.type == "dynamic" || this.targetInstance.type == "input") {
this.targetVarTest = eval(this.targetVar);
if (this.caching == true && (this.targetVarTest != "" && this.targetVarTest != undefined)){
if (this.enabletracing) trace ("--- LoadText caching : reading '"+this.targetVar+"' instead of loading");
if (this.enablehtml==true) {
this.targetInstance.html = true;
this.targetInstance.htmlText = this.targetVarTest;
}else this.targetInstance.text = this.targetVarTest;
this.onLoad(true);
}else if (this.caching==false || (this.caching==true && (this.targetVarTest=="" || !this.targetVarTest)) ||
(this.targetInstance.text.length==0 || this.targetInstance.text==this.waitingtext || this.targetInstance.text==this.originalText)
) {
if (this.enabletracing) trace ("--- LoadText target : "+this.targetInstance);
if (this.textfile != undefined && this.textfile != "" && this.textfile != ".txt") {
if (this.enabletracing) trace ("--- LoadText file : "+this.textfile);
if (this.waitingtext!="") this.targetInstance.text=this.waitingtext;
this.loadTextRaw = new LoadVars();
this.loadTextRaw.targetz=this.targetInstance;
this.loadTextRaw.enablehtml=this.enablehtml;
this.loadTextRaw.enabletracing=this.enabletracing;
this.loadTextRaw.targetVar=this.targetVar;
this.loadTextRaw.callback=this.callback;
this.loadTextRaw.parentObj=this;
this.loadTextRaw.onData = function(raw){
this.rawtemp = raw.loadTextReplace("\n","");
if(this.rawtemp!=""){ // find/make a real 404 test (get http header)
if (this.enablehtml==true) {
this.targetz.html = true;
this.targetz.htmlText = this.rawtemp;
}else this.targetz.text = this.rawtemp;
this.onLoad(true);
}else this.onLoad(false);
}
this.loadTextRaw.onLoad = function(success){
if(success){
this.parentObj.loadedz = this.loadedz = true;
if (this.targetVar!=undefined && this.targetVar!= "") {
set(this.targetVar,this.rawtemp);
if (this.enabletracing) {
if (eval(this.targetVar)!="" && eval(this.targetVar) != undefined) trace ("--- LoadText targetVar : var "+this.targetVar+" created");
else trace ("--- LoadText targetVar : error ! var "+this.targetVar+" wasn't created");
}
}
if (this.callback!=undefined && this.callback!="") {
this.callback=this.callback.LoadTextReplace("()","")
if (typeof(eval(this.callback))=="function") {
if (this.enabletracing) trace ("--- LoadText callback : function "+this.callback+"() called");
eval(this.callback)(true);
}else if (this.enabletracing) trace ("--- LoadText callback : '"+this.callback+"' is not a function or the path isn't correct");
}
}else if (this.enabletracing) trace ("--- LoadText error : loading failed");
}
this.loadTextRaw.load(this.textfile);
}else if (this.enabletracing) trace ("--- LoadText error : no textfile specified");
}else if (this.enabletracing) trace ("--- LoadText cache : text already loaded");
}else if (this.enabletracing) trace ("--- LoadText error : the target textfield isn't dynamic");
}else if (this.enabletracing) trace ("--- LoadText error : the target isn't a textfield");
}else if (this.enabletracing) trace ("--- LoadText error : no target textfield specified");
}
}else if (this.enabletracing) trace ("--- LoadText error : unable to create the class (already exists)");
#endinitclip
mais dans flash 8, à la place du texte, il écrit "undefined", je ne sais pas où se situe l'erreur...
Merci beaucoup de m'aider !
a2line