[Flash MX] Vinden van dynamic Text widths

Pagina: 1
Acties:

  • hobbit_be
  • Registratie: November 2002
  • Laatst online: 04-07-2025
Had van iemand gehoord dat dit 'tamelijk' eenvoudig kan met mx maar blijkbaar niet alle oplossing van FlashKit enzo hebben het hele alphabet letter per letter. Hier moet toch een betere oplossing voor zijn? Google leid tot niets en ook op GoT vond ik niets concreets.

  • KillR-B
  • Registratie: Mei 2002
  • Laatst online: 20-01 20:49
Het object TextFormat heeft een leuke functie daarvoor: getTextExtent("string")
Deze functie geeft de breedte en de hoogte terug.

Als je dan de echte breedte van een TextField wilt achterhalen kun je die opvragen met:
Flash ActionScript:
1
var breedte = textObj.getTextFormat().getTextExtent(textObj.text).width;

  • tie-rep
  • Registratie: Oktober 2001
  • Laatst online: 19-02 15:56

tie-rep

nu met ir. !

uit de help:
TextField.autoSize

If the value of autosize is "none", the text field behaves normally and does not automatically resize or align to match the text.

If the value of autosize is "left" and the text field line type is set to Multiline in the text Property inspector, then the text field expands or contracts its right and bottom sides to fit all contained text.

If the value of autosize is "left" and the text field line type is set to Multiline No Wrap in the text Property inspector, then the text field expands or contracts only its right side to fit all contained text.

If the value of autosize is "center", the text field auto-sizes, but the horizontal center of the text field stays anchored at the text field's original horizontal center position. The bottom side still expands to fit all contained text.

If the value of autosize is "right", the text field auto-sizes; but the left and bottom sides expand or contract. The top and right side remain in the same positions.


Example
The following sets the autosize property of the text field textField2 to "center".

textField2.autosize = "center"
edit:

bovenstaande oplossing is netter, maar het is maar net wat de toepassing is. :)

[ Voor 8% gewijzigd door tie-rep op 12-09-2003 20:00 ]


  • hobbit_be
  • Registratie: November 2002
  • Laatst online: 04-07-2025
KillR-B schreef op 12 September 2003 @ 19:56:
Het object TextFormat heeft een leuke functie daarvoor: getTextExtent("string")
Deze functie geeft de breedte en de hoogte terug.

Als je dan de echte breedte van een TextField wilt achterhalen kun je die opvragen met:
Flash ActionScript:
1
var breedte = textObj.getTextFormat().getTextExtent(textObj.text).width;
that's it! dat ik dat niet ben tegengekomen in mijn look door de search! - scandaleux! bedankt voor het antwoord _/-\o_

tie-rep: ja die dingen kende ik al - het ging me echter om het aanpassen van andere MC's naar gelang de breedte van de text (pixel wise). Ook bedankt

en topic mag vast closed - mensen die erop zoeken kunnen het nu ook eenvoudig terugvinden in GoT! ...

  • hobbit_be
  • Registratie: November 2002
  • Laatst online: 04-07-2025
hmm helaas werkt deze extens slechts voor niet HTML text? ook bij de andere lukt het me niet om gewoon te weten hoe groot de tekst is..

wat ik nodig heb: heb een menu - een item kan bijvoorbeeld html text ook bevatten. Nu kan het zijn dat de tekst niet meer op de verwachte breedte past - hij (of ik) moeten de tekst dan gaan wrappen. aangezien het menu niet genest is moet ik dus voor de volgende te weten wat de hoogte van bovenstaande (die te breed was) is.

dit heb ik maar
Flash ActionScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    
    //create dummy and empty but width of menu size
    _root.createTextField("new_text", 1000000, 100000, 0, aWidth, 0);
    var tTest_txt = _root.new_text;

     
     tTest_txt.selectable = false;

     //allow a wrap
     tTest_txt.multiline = 1;

     //let it wrap
     tTest_txt.wordWrap = 1;
     tTest_txt.border = false;
    tTest_txt.autoSize = "left";
 
    //assign a textformat from a designed MC - so designers don't need to AS
    tTest_txt.setNewTextFormat(aDesign_text.getTextFormat());
    tTest_txt.html = true;
    tTest_txt.htmlText = aText;
    return tTest_txt._height;


maar dit werkt dus niet... alle help is graag welkom!