# JSFL in AS2.0 - addNewText inside button

**URL:** <https://forum.kirupa.com/t/jsfl-in-as2-0-addnewtext-inside-button/261663>\
**Category:** flash\
**Created:** [May 29, 2008, 4:27pm UTC](https://forum.kirupa.com/t/jsfl-in-as2-0-addnewtext-inside-button/261663 "2008-05-29T16:27:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lobo](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lobo](https://forum.kirupa.com/u/lobo)\
**Post date:** [May 29, 2008, 4:27pm UTC](https://forum.kirupa.com/t/jsfl-in-as2-0-addnewtext-inside-button/261663/1 "2008-05-29T16:27:31Z")

</div>

Hi,  
I have a button in a library:

fl.getDocumentDOM().library.addNewItem(“button”, “Buttons/btn”);  
var closeBtn = fl.getDocumentDOM().library.findItemIndex(“Buttons/btn”);  
var closeBtn\_timeline = fl.getDocumentDOM().library.items[closeBtn].timeline;  
closeBtn\_timeline.addNewLayer(“btn text”,“normal”,false);  
closeBtn\_timeline.currentLayer = 0;  
closeBtn\_timeline.insertBlankKeyframe(3);

closeBtn\_timeline.currentLayer = 1;  
for (var i=1; i\<4; i++){  
closeBtn\_timeline.insertBlankKeyframe(i);  
}

and would like to addNewText in the second layer in first frame. I know how to add text on the main timeline, but was struggling to add it inside button.  
Any ideas?

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 29, 2008, 7:07pm UTC](https://forum.kirupa.com/t/jsfl-in-as2-0-addnewtext-inside-button/261663/2 "2008-05-29T19:07:56Z")

</div>

create a movieclip instance with a text field inside it in the library.  
then simply place a instance of it into the buttons timeline and apply text formattings.

---

<div class="post-metadata">

**Author:** ![lobo](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lobo](https://forum.kirupa.com/u/lobo)\
**Post date:** [May 30, 2008, 9:02am UTC](https://forum.kirupa.com/t/jsfl-in-as2-0-addnewtext-inside-button/261663/3 "2008-05-30T09:02:17Z")

</div>

[quote=sparkdemon;2333188]create a movieclip instance with a text field inside it in the library.  
then simply place a instance of it into the buttons timeline and apply text formattings.[/quote]

Sparkdemon, can you place a piece of JSFL code which will perform those actions.  
(I’m just starting with JSFL)

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 30, 2008, 5:22pm UTC](https://forum.kirupa.com/t/jsfl-in-as2-0-addnewtext-inside-button/261663/4 "2008-05-30T17:22:13Z")

</div>

// This code will need you to have a button in the library called “bar capped grey”

* * *

// selects the item in library called “bar capped grey” and starts editing it  
fl.getDocumentDOM().library.editItem(“bar capped grey”);

//add a new layer  
fl.getDocumentDOM().getTimeline().addNewLayer();

//add text box anywhere in the timeline of the button  
fl.getDocumentDOM().addNewText({left:-29, top:-10.1, right:-18.8, bottom:6.1});

// text object is autosizing  
fl.getDocumentDOM().setElementProperty(‘autoExpand’, true);

//write a value into the text object  
fl.getDocumentDOM().setTextString(‘Krishna’);

// use such a command to manually position it  
[//fl.getDocumentDOM](https://fl.getDocumentDOM)().moveSelectionBy({x:23.9, y:3.9});

//center align it  
fl.getDocumentDOM().align(‘vertical center’, true);  
fl.getDocumentDOM().distribute(‘horizontal center’, true);

// deselect everything  
fl.getDocumentDOM().selectNone();

// lock the layers  
fl.getDocumentDOM().getTimeline().setLayerProperty(‘locked’, true, ‘all’);

// done 🙂 return to main timeline (Stage)  
fl.getDocumentDOM().exitEditMode();

//-------------------------------------------

always open the history panel, then simulate what you want to do manually  
then go to the history panel copy the commands and paste it into the script editor.

then fine tune it to your needs… this saves time, as flash automatically  
writes jsfl code for you in the history panel.
