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

问题描述

我正在使用JSON在Flex中使用自定义的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属性的方式扩展Text类开始(例如,styleSheet:StyleSheet = null).然后创建一个包含以下样式的数组,这是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.

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

08-20 00:45