Smileyfield :: textfield avec smiley images

Description

voici un textfield qui prend en compte les smiley!
enfin!!!
il recherche les smiley et les transforme en image, grace a un xml qui permet la correspondance ascii->fichier.

Le code est pas super complexe, mais un debutant va vite etre pommé kan meme.

Tres utile pour une application de chat par exemple.

Source / Exemple :


XML_FILE = "smiley.xml";
SPACE = 4;
LEADING = 18;
MAXWIDTH = 200;
x = new XML();
x.ignoreWhite = true;
x.load(_root.XML_FILE);
x.onLoad = function(success) {
	_root.xmlloaded = true;
};
monFormat = new TextFormat();
monFormat.font = "arial";
monFormat.size = 12;
monFormat.type = "static";
//********************************************************************************
String.prototype.replace = function(str, rep, chr) {
	var t = (chr<0) ? this.substr(chr) : this.substr(0, chr);
	var s = str.length;
	var r = rep.length;
	var p = t.indexOf(str);
	while (p != -1) {
		t = t.substr(0, p)+rep+t.substr(p+s);
		p = t.indexOf(str, p+r);
	}
	return (chr) ? (chr<0) ? this.substr(0, this.length+chr)+t : t+this.substr(chr) : t;
};
String.prototype.transCode = function() {
	input = this;
	input = input.replace("é", "e");
	input = input.replace("è", "e");
	input = input.replace("à", "a");
	input = input.replace("ç", "c");
	input = input.replace("ë", "e");
	input = input.replace("ê", "e");
	input = input.replace("ù", "u");
	//input = input.toLowerCase();
	return input;
};
function isSmiley(input) {
	_root.local_rez = 0;
	ixml = 0;
	while (x.childNodes[0].childNodes[ixml] != undefined) {
		S_SMILEY = x.childNodes[0].childNodes[ixml].attributes.smiley;
		S_URL = x.childNodes[0].childNodes[ixml].attributes.url;
		S_W = x.childNodes[0].childNodes[ixml].attributes.w;
		S_H = x.childNodes[0].childNodes[ixml].attributes.h;
		ixml++;
		if (input == S_SMILEY) {
			_root.s_var = S_SMILEY+" "+S_URL+" "+S_W+" "+S_H;
			_root.local_rez = 1;
		}
	}
	return _root.local_rez;
}
MovieClip.prototype.write = function(input) {
	y_size += LEADING;
	x_size = 0;
	input = input.transCode();
	tbl = input.split(" ");
	for (i=0; i<=tbl.length-1; i++) {
		reading = tbl[i];
		if (!_root.isSmiley(reading)) {
			d++;
			this.createTextField("tf"+d, d, x_size, y_size, 0, 0);
			this["tf"+d]._visible = 1;
			this["tf"+d].text = reading;
			//this["tf"+d].setTextFormat(monFormat);
			this["tf"+d].textColor = "0x000000";
			this["tf"+d].selectable = false;
			this["tf"+d].autoSize = true;
			x_size += this["tf"+d].textWidth+SPACE;
			if (x_size>=MAXWIDTH) {
				x_size = 0;
				y_size += LEADING;
			}
		} else {
			sv = _root.s_var.split(" ");
			d++;
			this.smiley.duplicateMovieClip("smiley"+d, d);
			this["smiley"+d].loadMovie(sv[1]);
			this["smiley"+d]._x = x_size;
			this["smiley"+d]._y = y_size;
			this["smiley"+d]._visible = 1;
			x_size += SPACE+int(sv[2]);
		}
	}
	this["border"]._y = LEADING-1;
	this["border"]._width = MAXWIDTH;
	this["border"]._height = y_size+2;
	this["border"].swapDepths(d+100);
};

Conclusion :


pour fonctionner, fo tout decompresser dans le meme rep!
le swf dans le zip, sert a rien si le reste est pas decompressé...

Codes Sources

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.