单击颜色按钮并使用该颜色字体在文本区域中写入
我想做如下:
* click a "red" button
* write in textarea with red color font
* click "blue" button
* write in textarea with blue color font
使用 AS3 在 flash 10 中这不可能吗??????
我尝试使用 setTextFormat 但问题是在插入格式之前我必须有文本。
这就是我想要的:
* start writing in textarea with WHITE COLOR (eg: "abc")
* click BLUE COLOR BUTTON
* start writing in textarea with BLUE COLOR (eg: "abcdef" - abc in white and def in blue)
* click RED COLOR BUTTON
* start writing in textarea with RED COLOR (eg: "abcdefxyz" - abc in white and def in blue and xyz in red)
请有人告诉我该怎么做?
I want to do as follows:
* click a "red" button
* write in textarea with red color font
* click "blue" button
* write in textarea with blue color font
Isn't this possible in flash 10 using AS3 ??????
I tried using setTextFormat but the problem is i have to have text before inserting format on that.
This is what i want:
* start writing in textarea with WHITE COLOR (eg: "abc")
* click BLUE COLOR BUTTON
* start writing in textarea with BLUE COLOR (eg: "abcdef" - abc in white and def in blue)
* click RED COLOR BUTTON
* start writing in textarea with RED COLOR (eg: "abcdefxyz" - abc in white and def in blue and xyz in red)
Please somebody tell me how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该文档指出,如果您想在文本字段中写入任何内容之前更改文本的格式,请分配新的defaultTextFormat。否则,设置新格式将更改当前选择。
下面的解决方案通过将焦点保持在文本字段上来工作,因此当单击按钮时,文本字段仍然具有焦点。如果当前有一个选择,则该选择将变为蓝色或红色,具体取决于按下的按钮。如果没有选择,则应用新的 defaultTextFormat,而不更改以前的 defaultTextFormat,因为应用新格式时文本字段仍然具有焦点。
或者,如果您的程序中有其他与文本字段无关的按钮,并且应该使文本字段在单击时失去焦点,只需删除 fieldFocusOutHandler 函数并放置 stage.focus = field;在buttonClickHandler 方法内。如果这是一个问题,您还可以保留并定制 fieldFocusOutHandler 函数。
the documentation states that if you want to change the format of the text prior to writing anything in the text field to assign a new defaultTextFormat. otherwise, setting a new format will change the current selection.
the solution below works by maintaining the focus on the text field, so when the buttons are clicked the text field still has focus. if there is a current selection, the selection will change either blue or red, depending on which button is pressed. if there is no selection, a new defaultTextFormat is applied, without changing previous defaultTextFormats, since the text field still had focus when the new format was applied.
alternatively, if you have other buttons in your program that do not relate to the text field and should make the text field lose focus when clicked, just remove the fieldFocusOutHandler function and place stage.focus = field; inside the buttonClickHandler method. you could also keep and tailor the fieldFocusOutHandler function if this is an issue.
这是任何正在四处寻找的人的解决方案(感谢那些解决我问题的人)
在文本字段的更改处理程序中使用以下内容:
在按钮的单击处理程序中使用以下内容:
问候
Here is the solution for anyone who is looking around (thanks to those who solved my problem)
Use following in changehandler of textfield:
Use following in clickhandler of button:
Regards