Flex的TextFlow

TextFlow装载网页内容

示例代码:

textFlow = TextConverter.importToFlow(chapter.content,TextConverter.TEXT_FIELD_HTML_FORMAT,_config);

传入的第一个参数:包含html标签的字符串。
传入的第二个参数:第一个参数的格式。
传入的第三个参数:创建TextFlow的配置。

TextFlow中显示图片

TextFlow中图片资源会被处理为:InlineGraphicElement类的实例。这个类的source属性,如果只是给了一个URL,需要异步加载图片资源,资源加载情况会影响这个类的status属性 ,在status属性发生变化后,会抛出StatusChangeEvent事件。想要让TextFlow显示图片,需要监听TextFlow抛出的这个事件,并调用 IFlowComposer.updateAllControllers()。

TextFlow中控制图片的尺寸

上述InlineGraphicElement 类中,有几个属性和图片的尺寸相关,分别是:
- width 和 height 属性
- measuredWidth 和 measuredHeight 属性,表示加载时图形的宽度或高度
- actualWidth 和 actualHeight 属性,表示通过 width 或 height 以及 measuredWidth 或 measuredHeight 计算得到的图形的实际显示和合成宽度和高度

加载完图片后,图片的measuredWidth和measuredHeight是图片的实际尺寸,如果这两个值大于显示的限制,修改这个类实例的 width 和 height 值,就可以控制图片实际显示的大小。

以下示例代码,判断如果图片如果超出尺寸,做相应的缩小处理:

var imgElement:InlineGraphicElement=evt.element as InlineGraphicElement;
trace(">>>>>>"+imgElement.source);
trace("0w:"+imgElement.width,imgElement.measuredWidth,imgElement.actualWidth);
trace("0h:"+imgElement.height,imgElement.measuredHeight,imgElement.actualHeight);

var wFlag:Boolean=imgElement.measuredWidth>=cWidth;
var hFlag:Boolean=imgElement.measuredHeight>=_containerHeight;
if(wFlag||hFlag)
{
    trace("1w:"+imgElement.width,imgElement.measuredWidth,imgElement.actualWidth);
    trace("1h:"+imgElement.height,imgElement.measuredHeight,imgElement.actualHeight);
    if(wFlag&&hFlag)
    {
        var wRate:Number=imgElement.measuredWidth/cWidth;
        var hRate:Number=imgElement.measuredHeight/cHeight;
        if(wRate>=hRate)
        {
            imgElement.width=cWidth;
            imgElement.height=imgElement.measuredHeight/wRate;
        }else
        {
            imgElement.height=cHeight;
            imgElement.width=imgElement.measuredWidth/hRate;
        }
    }else
    {
        if(hFlag)
        {
            imgElement.height=cHeight;
        }else if(wFlag)
        {
            imgElement.width=cWidth;
        }
    }
    trace("2w:"+imgElement.width,imgElement.measuredWidth,imgElement.actualWidth);
    trace("2h:"+imgElement.height,imgElement.measuredHeight,imgElement.actualHeight);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值