Question

I am struggling with JSFL text fields. I want to put a text field on stage with a static width of 220px. So if the string that is put into the text is longer than that it auto wraps to the next line.

Any suggestions?

doc = fl.getDocumentDom();
doc.addNewText({left:0, top:0, right:220, bottom:200});
doc.setElementProperty("textType", "static");
doc.setElementProperty("width", 220); // fails miserably -- text field is huge
doc.setTextString(value);

// Setting the width after the text is entered scrunches the text -- doesn't wrap
// doc.selection[0].width = 220;
Was it helpful?

Solution

So I took a look at your JSFL issue and through this I have found that I never want to work with Flash text boxes in JSFL again...haha. I was able to create a text box with a width of 220 px on the stage and have it populated with text using the code below. One of the main issues I ran into was that static text boxes don't allow you to adjust the line type property so you create one as dynamic first and set it to multiline, then set it to a static text box, and for some reason that worked.

    // Add Text To Stage - Andrew Doll
    // 09-13-13

    var dom = fl.getDocumentDOM();
    if (dom == null)
    {
        alert('Please open a file.');
    }
    else
    {
        // String of text to test with.
        var value = 'This is a test string to make sure what I am doing is working     correctly.';

    // I have no idea why but for some reason Flash will add 2px to the width of the box created so I just used 218 instead of 220.

    // Add a text box to the stage.
    dom.addNewText({left:0, top:0, right:218, bottom:200});

    // Set the size of the text bounding box.
    dom.setTextRectangle({left:0, top:0, right:218, bottom:200});

    // Static text boxes don't allow you to use lineType so use dynamic then set to static afterwards.
    dom.setElementProperty('textType', 'dynamic');

    // Allows multiline text.
    dom.setElementProperty('lineType ', 'multiline');

    // Limits the text box from expanding in size.
    dom.setElementProperty('autoExpand ', false);

    // Set the text box to static.
    dom.setElementProperty('textType', 'static');

    // Set the string of text into the text box.
    dom.setTextString(value);
}

I hope this helps you out. Let me know how it works out for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top