Flash Lite:html文本格式
简而言之
我有一个 Flash 应用程序(为 Flash Lite - ActionScript 2 制作)。 当我在应用程序中加载 XML 文件并在对象中处理它时。我在文本字段中获得了正确的 html 输入。
但是,如果我对对象进行硬编码,所有 html 标签都会从 .htmlText 属性中消失,并且文本前面会放置代码。我打算对对象进行硬编码,因为加载速度比 xml 快得多。
长话短说:string.html = true;
删除所有span标签,而我需要这些标签。如何获取文本字段的 htmlText 中的 span 标签?
下面的更多信息
在我的应用程序中,我创建文本字段,在其中放入一些文本,然后设置正确的 x 和 y 值,以便将它们很好地放置在彼此之下。
在函数内部:
//ABOVE I CREATE TEXTFIELD USING THE .CREATETEXTFIELD FUNCTION
this["text" + this._textFieldCounter].html = true;
this["text" + this._textFieldCounter].multiline = true;
this["text" + this._textFieldCounter].wordWrap = true;
this["text" + this._textFieldCounter].autoSize = true;
this["text" + this._textFieldCounter].styleSheet = this._styleSheet;
this["text" + this._textFieldCounter].condenseWhite = true;
this["text" + this._textFieldCounter].htmlText = "<span class=\"page\">" + strHtmlText + "</span>";
//trace(this["text" + this._textFieldCounter].htmlText);
当我跟踪 htmlText 时,
<P ALIGN="LEFT">
<FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">
//here comes the strHtmlText
</FONT>
</P>
Flash 会自动将这些 p 和 font 标记放在我的文本前面。所以我的样式表不会显示正确的样式。我如何摆脱初始对齐和字体标签,但仍将文本字段保留为 html?
编辑
通过设置文本格式,我找到了解决这个问题的方法......但是
我有一个新问题:
在我的 strHtmlText 中有 span 标签( blabla
),但这会被过滤掉。这是为什么呢?如果没有这些样式,我的样式表不会执行任何操作。
(文本从数组加载)
IN A NUTSHELL
I have a flash application (made for flash lite - actionscript 2).
When I load in my application an XML File and I process it in an object. I get the correct html input in a textfield.
However if I hardcode the object, all html tags disappear from the .htmlText attribute and there is code placed in front of the text. It is my intention to hardcode the object, since the loading goes a lot fast then xml.
long story short: string.html = true;
deletes all span tags, while I need those. How do I get the span tags in the htmlText of my textfield?
MORE INFO BELOW
In my application I create textfields put some text in them and then set the correct x and y value so they are all nicely put beneath eachother.
inside the function:
//ABOVE I CREATE TEXTFIELD USING THE .CREATETEXTFIELD FUNCTION
this["text" + this._textFieldCounter].html = true;
this["text" + this._textFieldCounter].multiline = true;
this["text" + this._textFieldCounter].wordWrap = true;
this["text" + this._textFieldCounter].autoSize = true;
this["text" + this._textFieldCounter].styleSheet = this._styleSheet;
this["text" + this._textFieldCounter].condenseWhite = true;
this["text" + this._textFieldCounter].htmlText = "<span class=\"page\">" + strHtmlText + "</span>";
//trace(this["text" + this._textFieldCounter].htmlText);
When I trace the htmlText I get
<P ALIGN="LEFT">
<FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">
//here comes the strHtmlText
</FONT>
</P>
Flash automatically put those p and font tag in front of my text. So my stylesheet won't show the correct style. How do i get rid of the initial align and font tag but still keep the textfield as html?
EDIT
By setting a textformat I have found a way around this problem... HOWEVER
I have a new problem:
In my strHtmlText there are span-tags ( <span class="text-in">blabla</span>
), but this gets filtered out. Why's that ? my stylesheet doesn't do anything without those styles.
(text is loaded from an array)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它一定与您将属性分配给 TextField 的顺序有关。它应该是:1.设置
field.html
为true
,2.分配styleSheet
,3.设置htmlText
。styleSheet 必须在分配 htmlText 之前设置 - 我最初发布了一个指向 as3 文档的链接,但对于 AS2 和 AS3 都是如此。
试试这个:将 TextField 放在新的 AS2 FLA 的舞台上。将其类型设置为动态。将其命名为“
_textField
”。将字体设置为 Verdana、16px、黑色。输入“错误”。或类似的文本字段,以便其中包含一些文本。单击“嵌入字体”,确保包含足够数量的字母,例如 ascii 或 Latin-1。在时间轴上,将此代码输入到影片的第一帧中。
现在,当您运行该程序时,它应该将文本更改为“这是一个测试”,将颜色更改为红色,并将字体大小更改为 12 像素。在我的电脑上确实如此。此外,跟踪打印的文本与分配给
htmlText
的文本完全相同。现在返回并交换分配
styleSheet
和htmlText
属性的行。重新运行程序。它将包含您抱怨的所有额外标签。It must have something to do with the order in which you assign the properties to the TextField. It should be: 1. set
field.html
totrue
, 2. assignstyleSheet
, 3. sethtmlText
.The styleSheet must be set before the htmlText is assigned - I originally posted a link to the as3 documentation, but this is true for both AS2 and AS3.
Try this: Put a TextField on the stage of a new AS2 FLA. Set its type to dynamic. Name it to "
_textField
". Set the font to Verdana, 16px, Black. Enter "Error." or something similar into the TextField, so that it has some text in it. Click "Embed fonts", be sure to include a sufficient amount of letters, like ascii or Latin-1.On the timeline, enter this code into the first frame of the Movie.
Now when you run the program, it should change the text to "This is a test", the color to red and the font size to 12 px. It does on my computer. Also, the trace prints the exact same text that is assigned to
htmlText
.Now go back and exchange the lines assigning the
styleSheet
andhtmlText
properties. Re-run the program. It will have all the extra tags you were complaining about.