开发者

spark Text area height adjust to content

开发者 https://www.devze.com 2023-02-25 16:19 出处:网络
i want to adjust the size of my text area in action script based on the text i put inside dynamically, but absolutly don\'t know how to do that... searched a lot for nothing. Here is my code if it can

i want to adjust the size of my text area in action script based on the text i put inside dynamically, but absolutly don't know how to do that... searched a lot for nothing. Here is my code if it can help you situate the problem. I want to adjust the height of msgLabel to the content.

Thanks a lot ;).

public function createTweet(tweet:XML, lineName:String, isTweetInList:Boolean):IVisualElement{
    var authorS:String = tweet.posterName;
    var tweetID:String = tweet.tweetID;

    //Main vertical group
    var vg:VGroup = new VGroup();
    vg.percentWidth = 100;
    if(!isTweetInList){
        //Add the new VGroup to the tweetTabHolder
        tweetTabHolder[tweetID+lineName] = vg;

        //Add the new tweetID to the tweet posted by an author
        if(tweetByLineByAuthor[authorS] == null)
            tweetByLineByAuthor[authorS] = new Dictionary();
        if(tweetByLineByAuthor[authorS][lineName] == null)
            tweetByLineByAuthor[authorS][lineName] = new ArrayList();
        tweetByLineByAuthor[authorS][lineName].addItem(tweetID);
    }

    vg.setStyle("backgroundAlpha", 0);
    vg.paddingLeft = 20;

    var sp0:Spacer = new Spacer();
    sp0.height = 10;
    vg.addElement(sp0);

    //Tweet Content
        //Author
    var hgA:HGroup = new HGroup();
    var aSpacer:Spacer = new Spacer();
    aSpacer.width = 10;
    hgA.addElement(aSpacer);
    var authorLabel:RichText = new RichText();
    authorLabel.text = authorS;
    authorLabel.setStyle("fontSize",20);
    authorLabel.setStyle("fontWeight",FontWeight.BOLD);
    authorLabel.setStyle("color",authorColor);
    authorLabel.addEventListener("click",authorClickHandler);
    authorLabel.addEventListener(MouseEvent.MOUSE_OVER,authorFocusInHandler);
    authorLabel.addEventListener(MouseEvent.MOUSE_OUT,authorFocusOutHandler);
    hgA.addElement(authorLabel);
    if(tweet.posterName == userNameLogged || isTweetInList){
        var abs1:Spacer = new Spacer();
        abs1.width = 25;
        hgA.addElement(abs1);
        hgA.addElement(createDeleteTweetButton(tweetID,vg, isTweetInList));
        var abs2:Spacer = new Spacer();
    }
    if(!isTweetInList){
        abs2.width = 4;
        hgA.addElement(abs2);
        hgA.addElement(createFavorisButton(tweetID));
    }
    vg.addElement(hgA);
        //Msg
    var hgM:HGroup = new HGroup();
    var mSpacer:Spacer = new Spacer();
    mSpacer.width = 15;
    hgM.addElement(mSpacer);
    var msgLabel:TextArea = new TextArea();
    hgM.addElement(msgLabel);
    hgM.percentWidth = 100;
    msgLabel.percentWidth = 100;
    msgLabel.text = tweet.msg;
    msgLabel.setStyle("fontSize",12);
    msgLabel.setStyle("color",msgColor);
    msgLabel.editable = false;
    msgLabel.setStyle("lin开发者_如何转开发eBreak", "toFit");
    vg.addElement(hgM);

    //Date
    var hgD:HGroup = new HGroup();
    var dSpacer:Spacer = new Spacer();
    dSpacer.width = 10;
    hgD.addElement(dSpacer);
    var dateLabel:Label = new Label();
    dateLabel.text = tweet.postingDate.date;
    dateLabel.setStyle("fontSize",10);
    dateLabel.setStyle("color",dateColor);
    hgD.addElement(dateLabel);
    vg.addElement(hgD);

    var sp1:Spacer = new Spacer();
    sp1.height = 10;
    vg.addElement(sp1);
    var hr:HRule = new HRule();
    hr.percentWidth = 90;
    hr.x = 20;
    vg.addElement(hr);
    return vg;
}


First off, why are you using Actionscript when your application is clearly Flex? You could reduce that mess of code by 2/3. Also, last I checked they all resize to their content unless you specify their dimensions. Either way, here's an example which works great:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            [Bindable] private var someText:String = "Enter long text here.";
        ]]>
    </fx:Script>
    <s:RichEditableText selectable="true" editable="false" text="{someText}" multiline="true" width="100%" />

</s:Application>
0

精彩评论

暂无评论...
验证码 换一张
取 消