JSON 作为 Flex 中的 HTML 数据 - 超链接翻转 [英] JSON as HTML data in Flex - Hyperlink Rollovers

查看:17
本文介绍了JSON 作为 Flex 中的 HTML 数据 - 超链接翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Flex 中使用 JSON 解析带有自定义 html 标签的 HTML 数据.Flex 对 HTML 的支持非常少,所以我想知道是否可以对这些链接进行简单的字体颜色更改翻转效果.目前我发现Flex只支持少数HTML标签,但也通过Flex的whack CSS方法支持CSS.

I am using JSON to parse HTML data with customized html tags in Flex. Flex's support for HTML is pretty minimal, so I am wondering if it's possible to do a simple font color change rollover effect on these links. Currently I have found that Flex only supports a few HTML tags, but also supports CSS through Flex's whack CSS methods.

我可以通过外部 CSS 文件操作在我的 JSON 文件中编写的 HTML 吗?还是最好在 JSON 文件中使用一个简单的标签?

Can I manipulate HTML that is written in my JSON files through an external CSS file? Or better still using a simple tag with the JSON file?

推荐答案

简短回答:我认为没有灵丹妙药.这会很痛苦.

Short answer: I don't think there's a magic bullet for this. It's going to be a lot of pain.

您可以通过添加静态 StyleSheet 属性(例如,styleSheet:StyleSheet = null)的方式扩展 Text 类.然后创建一个包含以下样式的数组,这是 Flex 唯一支持的样式:

You can start by extending the Text class in a way that adds a static StyleSheet property (e.g., styleSheet:StyleSheet = null). Then create an array which contains the following styles, the only ones supported by Flex:

listOfStyles:Array = ['fontSize', 'color', 'fontWeight', 'fontFamily', 'fontStyle', 'textDecoration'];

然后您必须初始化 StyleManager.selectors,创建您将要使用的选择器数组.基本上,您要找到A"标签并将上面的 listOfStyles 添加到它,然后为每个样式创建一个新的 CSSStyleDeclaration.

Then you have to initialize the StyleManager.selectors, creating an array of selectors you are going to use. Basically, you are finding the "A" tag and adding the listOfStyles above to it, then creating a new CSSStyleDeclaration for each of those styles.

这将允许您将上述样式应用于扩展类的 htmlText 属性.到现在为止还挺好.这使您可以在加载时使用外部样式表为锚标记设置不同的样式.但是,要应用翻转效果,其中每个链接在 HTML 中的翻转时更改颜色,这将是有问题的,因为 MouseEvent.MOUSE_OVER 将应用于整个类,而不是其中的单个 HTML 元素.您必须弄清楚鼠标是否位于该 HTML 文本中的锚点上(并非不可能,但我现在没有时间解决这个问题)并在其中更改您的选择器.这将涉及获取文本范围,这总是意味着很多工作.当客户希望表情符号出现在文本流中(其他 Flex 的 HTML 实现无法支持)时,我不得不把它弄得一团糟.

This will allow you to apply the above-named styles to the htmlText property of your extended class. So far so good. This enables you to set different styles to your anchor tags upon load, using an external stylesheet. To apply a rollover effect, however, where each link changes color on rollover within the HTML, would be problematic, since MouseEvent.MOUSE_OVER would apply to the class as a whole, not the individual HTML elements within it. You would have to figure out if the mouse was over an anchor within that HTML text (not impossible, but I don't have time to work that out right now) and change your selector within that. It would involve getting the text range, and that always means a lot of work. I had to mess with that when a client wanted emoticons to appear in the text flow (something else Flex's implementation of HTML fails to support) and it was extremely gnarly.

我相信 Flex 4 会为这类事情增加更多的原生支持,但我还没有专门研究过.

I believe Flex 4 is going to add more support natively for this kind of thing, but I haven't researched that specifically.

抱歉,我没有灵丹妙药给你,但我希望这能让你对这个话题有所了解.

Sorry I don't have a magic bullet for you, but I hope this sheds a little light on the topic.

这篇关于JSON 作为 Flex 中的 HTML 数据 - 超链接翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆