A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: change alignment dyn.textfield from a button

  1. #1
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611

    change alignment dyn.textfield from a button

    Hi there,

    Anyone know how I can make a dynamic tekstfield change it's alignment from left to right when hitting a button?Possible?How?

    Big thx in advance


    Grtz,

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    you could use the text format object,

    code:

    // create the text format object
    var fmt = new TextFormat();
    fmt.align = "left";

    // and place the text hello world in a textfield (instance name txt)
    txt.text = "hello world";
    txt.setTextFormat(fmt);

    // create an onPress event for the button (instance name btn)
    btn.onPress = function() {
    // if the alignment was left set it to right, otherwise set it to left
    fmt.align = fmt.align == "left" ? "right" : "left";
    // apply the formating to the text field
    txt.setTextFormat(fmt);
    };


  3. #3
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    Hi catbert303,

    My tekst is loaded from an xml file.So this line is not needed?
    txt.text = "hello world";

    This is the action I use to send my tekst through my dyn.textfield

    Actions.subtitel = function(msg) {
    trace(msg);
    subtitel_txt.html = true;
    subtitel_txt.htmlText = msg;
    };

    So subtitel_txt is the instancename of my dyn.textfield. how can I make a button change the alignment of the Dyn.textfield(subtitel_txt) from "left" to "right"?Help:s.

    Grtz,

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    code:

    btn.onPress = function() {
    fmt = new TextFormat();
    fmt.align = "right";
    subtitel_txt.setTextFormat(fmt);
    };



    would make the text contained in the field subtitel_txt right aligned when the button (instance name btn) was pressed

  5. #5
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    thx works like a charm. Your a star

    Grtz,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center