Flex 中 JSON 作为 HTML 数据 - 超链接翻转

发布于 2024-08-22 01:05:52 字数 219 浏览 10 评论 0原文

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

我可以通过外部 CSS 文件操作 JSON 文件中写入的 HTML 吗?或者更好地仍然使用带有 JSON 文件的简单标签?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甲如呢乙后呢 2024-08-29 01:05:52

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

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

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

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

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

我相信 Flex 4 将会为本机添加更多对此类事物的支持,但我还没有具体研究过。

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

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

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'];

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.

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.

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.

国粹 2024-08-29 01:05:52

我不经常使用 Flex,所以没有太多深入的框架知识,但我想我
需要类似的东西:

做一个简单的字体颜色改变翻转
效果

这里是一个片段:

var linkRegEx:RegExp = new RegExp("(https?://)?(www\\.)?([a-zA-Z0-9_%]*)\\b\\.[a-z]{2,4}(\\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\\.[a-z]*)?(:\\d{1,5})?","g");
var link:String = 'generic links: www.google.com http://www.yahoo.com  stackoverflow.com';
link = addLinks(linkRegEx,link);
textField.htmlText = link;//textField is a TextField I have on stage

function addLinks(pattern:RegExp,text:String):String{
    var result = '';
    while(pattern.test(text)) result = text.replace(pattern, "<font color=\"#0000dd\"><a href=\"
amp;\">
amp;</a></font>");
    if(result == '') result+= text;//if there was nothing to replace
    return result;
}

我只是使用内联字体标签,css可能会更好。这是我的原文问题

哈特哈,
乔治

I don't use Flex often so not much in depth framework knowledge, but I think I
needed to something similar:

do a simple font color change rollover
effect

Here is a snippet:

var linkRegEx:RegExp = new RegExp("(https?://)?(www\\.)?([a-zA-Z0-9_%]*)\\b\\.[a-z]{2,4}(\\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\\.[a-z]*)?(:\\d{1,5})?","g");
var link:String = 'generic links: www.google.com http://www.yahoo.com  stackoverflow.com';
link = addLinks(linkRegEx,link);
textField.htmlText = link;//textField is a TextField I have on stage

function addLinks(pattern:RegExp,text:String):String{
    var result = '';
    while(pattern.test(text)) result = text.replace(pattern, "<font color=\"#0000dd\"><a href=\"
amp;\">
amp;</a></font>");
    if(result == '') result+= text;//if there was nothing to replace
    return result;
}

I just used inline font tag, css might be better. Here is my original question.

HTH,
George

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文