-
ugh! i've been working on a text editor for (what feels like years) now...
can anybody help me figure out why, if i select some text and make it bold (or whatever) then i select new text and apply a new format to it (say, italic) it makes the text italic, but it also makes it bold?
i can't get it to stop applying the current & previous format.
you can check it out here:
http://www.bytestudios.com/lys/textedit5.html
and here's my <dread> code:
myTextFormat = new TextFormat();
myTextFormat.bold = false;
myTextFormat.italic = false;
myTextFormat.underline = false;
bold_button.setLabel("bold");
under_button.setLabel("underline");
italic_button.setLabel("italic");
left_button.setLabel("LEFT");
center_button.setLabel("center");
right_button.setLabel("right");
myfonts = TextField.getFontList();
fontList.setDataProvider(myfonts);
fontList.setSize(300);
fontList.setSelectedIndex(20);
fontSizes = new Array(6, 8, 10, 12, 14, 16, 18, 20, 24, 28, 32, 40, 48, 56, 64);
fontSize.setDataProvider(fontSizes);
fontList.setSelectedIndex(4);
fontList.setChangeHandler("myHandler");
function myHandler(component) {
myTextFormat.font = fontList.getSelectedItem().label;
myTextField.setTextFormat(myTextFormat);
}
fontSize.setChangeHandler("myHandler2");
function myHandler2(component) {
myTextFormat.size = fontSize.getSelectedItem().label;
myTextField.setTextFormat(myTextFormat);
}
bold_button.setClickHandler("makeBold");
function makeBold(component) {
myTextFormat.bold = true;
myTextField.setTextFormat(_level0.control.starttxt , _level0.control.endtxt, myTextFormat);
}
function makeBold() {
if (myTextFormat.bold) {
myTextFormat.bold = false;
bold_button.setLabel("bold");
} else {
myTextFormat.bold = true;
bold_button.setLabel("BOLD");
}
myTextField.setTextFormat(_level0.control.starttxt , _level0.control.endtxt, myTextFormat);
}
under_button.setClickHandler("makeUnder");
function makeUnder(component) {
myTextFormat.underline = true;
myTextField.setTextFormat(_level0.control.starttxt , _level0.control.endtxt, myTextFormat);
}
function makeUnder() {
if (myTextFormat.underline) {
myTextFormat.underline = false;
under_button.setLabel("underline");
} else {
myTextFormat.underline = true;
under_button.setLabel("UNDERLINE");
}
myTextField.setTextFormat(_level0.control.starttxt , _level0.control.endtxt, myTextFormat);
}
italic_button.setClickHandler("makeItalic");
function makeItalic(component) {
myTextFormat.italic = true;
myTextField.setTextFormat(_level0.control.starttxt , _level0.control.endtxt, myTextFormat);
}
function makeItalic() {
if (myTextFormat.italic) {
myTextFormat.italic = false;
italic_button.setLabel("italic");
} else {
myTextFormat.italic = true;
italic_button.setLabel("ITALIC");
}
myTextField.setTextFormat(_level0.control.starttxt , _level0.control.endtxt, myTextFormat);
}
left_button.setClickHandler("makeLeft");
function makeLeft(component) {
myTextFormat.align = "left";
left_button.setLabel("LEFT");
center_button.setLabel("center");
right_button.setLabel("right");
myTextField.setTextFormat(myTextFormat);
}
center_button.setClickHandler("makeCenter");
function makeCenter(component) {
myTextFormat.align = "center";
left_button.setLabel("left");
center_button.setLabel("CENTER");
right_button.setLabel("right");
myTextField.setTextFormat(myTextFormat);
}
right_button.setClickHandler("makeRight");
function makeRight(component) {
myTextFormat.align = "right";
left_button.setLabel("left");
center_button.setLabel("center");
right_button.setLabel("RIGHT");
myTextField.setTextFormat(myTextFormat);
}
and here's the code that's in my "control" mc:
woohoo = Selection.getFocus();
if (woohoo eq "_level0.myTextField") {
starttxt = Selection.getBeginIndex();
endtxt = Selection.getEndIndex();
cursor = Selection.getCaretIndex();
}
thanks for any and all help!!
lys
-
It's quite simple really. You reuse the same TextFormat object for all of your functions. If the italic function does this a myTextFormat.italic = true, then italic is still true when you press the bold button, and so it applies both italic and bold formatting.
What I would do is use a tmpTf = myTextFormat.getTextFormat( _level0.control.starttxt, _level0.control.endtxt ), then use tmpTf.whatever = true, then apply the temp formatting object to your textfield.
Hope this helps.
-
THANK YOU!!!! duh! it's so obvious to me know - it worked great!
lys
-
awsome! works great. how do you save now?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|