zoukankan      html  css  js  c++  java
  • 神奇的TextField(1)

    先看一大段测试代码,每个小方法的注释行是输出结果。

    private var text_content:TextField;

    private function textFieldDemo():void{
    text_content=new TextField();
    addChild(text_content);
    textFieldDemo26();
    }

    private function textFieldDemo1():void{
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    //text正常显示,输出100 100 30
    }

    private function textFieldDemo12():void{
    text_content.multiline=true;
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    //text正常显示,输出100 100 30
    }

    private function textFieldDemo13():void{
    text_content.wordWrap=true;
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    //text正常显示,输出100 100 100
    }

    private function textFieldDemo14():void{
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.wordWrap=true;
    trace(text_content.width);
    //text正常显示,输出100 100 30 30
    }

    private function textFieldDemo15():void{
    text_content.width=222;
    text_content.wordWrap=true;
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    //text正常显示,输出222 222 222
    }

    private function textFieldDemo16():void{
    text_content.text="nihao";
    trace(text_content.width);
    text_content.wordWrap=true;
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    //text正常显示,输出100 100 100
    }

    private function textFieldDemo2():void{
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    //text正常显示,输出100 4 30
    }

    private function textFieldDemo22():void{
    text_content.multiline=true;
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    //text正常显示,输出100 4 30
    }

    private function textFieldDemo23():void{
    text_content.wordWrap=true;
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    //text正常显示,输出100 100 100
    }

    private function textFieldDemo24():void{
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    text_content.wordWrap=true;
    trace(text_content.width);
    //text正常显示,输出100 4 30 30
    }

    private function textFieldDemo25():void{
    text_content.width=222;
    text_content.wordWrap=true;
    trace(text_content.width);
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    //text正常显示,输出222 222 222
    }

    private function textFieldDemo26():void{
    text_content.width=222;
    text_content.autoSize="left";
    trace(text_content.width);
    text_content.wordWrap=true;
    trace(text_content.width);
    text_content.text="nihao";
    trace(text_content.width);
    //text"不显示"(界面上看不到textfield),输出4 4 4
    }

    仔细分析上面的代码执行结果,可以得出如下结论:

    1.设置wordwrap,mulitline不会导致width值发生变化,但设置wordwrap可能会对width的值产生影响。

    2.设置autosize属性,当wordwrap为false时导致width值发生变化,当wordwrap为true时不对width产生影响。

    3.设置text属性,当wordwrap为false并且autosize不为none时,width值才发生变化。否则不对width产生影响。

    就是说,wordwrap autosize text对width都有决定作用。

  • 相关阅读:
    【JavaP6大纲】SpringCould篇:什么是微服务
    【JavaP6大纲】SpringCould篇: Spring Boot 和 Spring Cloud,谈谈你对它们的理解?
    【JavaP6大纲】分布式会话篇:集群部署时的分布式 Session 如何实现?
    【JavaP6大纲】SpringCould篇:Spring Cloud 和 Dubbo 有哪些区别?
    【JavaP6大纲】SpringCould篇:服务发现组件 Eureka 的主要调用过程?Eureka 和 Zookeeper 都可以提供服务注册与发现的功能,它们有什么区别?
    【JavaP6大纲】SpringCould篇:熔断框架如何做技术选型?选用 Sentinel 还是 Hystrix?
    【JavaP6大纲】SpringCould篇:如何限流?在工作中是怎么做的?说一下具体的实现?
    【JavaP6大纲】SpringCould篇:常用组件底层实现
    【JavaP6大纲】MySQL篇:SQL的整个解析、执行过程原理、SQL行转列?
    如何将百度搜索嵌入到站点中!
  • 原文地址:https://www.cnblogs.com/tianlanliao/p/3671882.html
Copyright © 2011-2022 走看看