I was wondering what could be the reason for strange behavior of html rendereed text in predefined textField exported to flash 8. So, I decided to take a look into what happen to textField object while swf is playing.
I used this to examine properties of predefined textField.
CODE
dumpObj=function(_obj) {
ASSetPropFlags(_obj, null, 6, 1);
_root.inf="";
for (z in _obj) {
_root.infoText+=z+" = "+_obj[z]+"\n";
}
};
dumpObj(myTextField);
// This assumes that you have predefined textField myTextField and infoText.
And I found that property _text.multiline mysteriously becomes FALSE no matter what is set within swishmax IDE. Well, this is the reason why line break
tag is not rendered properly. Why ?
Actually on initialising textField flash renders
by inputing text within paragraf
tag. Let’s see this practically. Suppose that we have this text:
A
B
Flash will render it to
A
B
, actually it will be like this:
htmlText=
A
B
But predefined dynamic textField created with swishmax will render it like this:
htmlText =
AB
Knowing that swishmax keeps original text in property textField.text I tried this:
myTextField._text.multiline = true;
myTextField._text.htmlText = myTextField.text;
CODE
MovieClip.prototype.cbxDumpText=function(_c) {
if (this._text.text && this._text.variable) {
_t=this._text;
for (z in _c) _t[z] = _c[z];
if (_t.html) _t.htmlText = this.text;
}
};
Works fine with text, but position of externally lodaed image is incorrect so, this solution was just half a way to success.
Idea was to dynamically create another textFiled that will have all predefined values of original myTextField but with some corrections, like multiline = true.
And here it is:
This should be added into _root of main swf:
CODE
onload() {
MovieClip.prototype.cbxDumpText=function(_c) {
if (this._text.text && this._text.variable) {
var _t, _o = new Object(), tx = this.text, tFormat = this._text.getNewTextFormat();
if (this._text.stylesheet) this._text.styleSheet=this._text.stylesheet;
for (z in this._text) _o[z] = this._text[z];
_t = this._parent.createTextField(this._name, this.getDepth(), this._x, this._y, this._width, this._height);
_t.setNewTextFormat(tFormat);
for (z in _t) _t[z] = _o[z];
for (z in _c) _t[z] = _c[z];
if (_t.html) _t.htmlText = tx;
}
};
}
In myTextFiled add actionscript code:
CODE
onload() {
var cbx = { multiline:true, condenseWhite:true, variable:"content" };
this.cbxDumpText(cbx);
}
var cbx explanation:
this is obj which will pass new values of certain properties.
1. multiline = true; // set this to true if your textField is multiline, smax fails to set this property.
2. condenseWhite = true; // set this only if you need it
3. variable – this is tricky, name of variable should be passed as stringName, that is why it is “content”, whatever you set (or you don't have to) as variable for myTexField in swishmax IDE will be overwritten with this new variable name. (this example assumes that variable name is “content”, buit it can be whatever you want).
You can predefine some other properties as well, but it does not concern this bug, so it is up to you.
When swishzone fix this bug, you can simply change this prototype to:
CODE
MovieClip.prototype.cbxDumpText=function(_c) {
return null;
}
Another solution would be to create new swi/swf file with this prototype only and to load it to _root, after swishzone fix this bug, just remove that swf file.
Please NOTE: this will work only with predefined dynamic textField objects created in swishmax IDE, but not with statics! There are some tricks for static textField objects, but more about that maybe next time.
As we all know, example is better than 1000 words, so take a look into attached file.
Happy New Year and Swishing!