以下範例,我使用 mxml 製作,請參考符合你需求的部分使用即可
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
minWidth="800" minHeight="600"
layout="vertical"
creationComplete="application1_creationCompleteHandler(event)">
<mx:Script>
<![CDATA[
import mx.events.ColorPickerEvent;
import mx.events.FlexEvent;
import mx.events.ListEvent;
[Bindable]
private var sizeList:Array = [12, 16, 20, 24, 30, 36];
[Bindable]
private var fontList:Array = ["Arial", "Courier New", "Times New Roman"];
private var _txt:TextField;
protected function
application1_creationCompleteHandler(event:FlexEvent):void
{
_txt = new TextField();
_txt.width = 400;
_txt.height = 300;
_txt.border = true;
_txt.background = true;
_txt.backgroundColor = 0xffffff;
_txt.type = TextFieldType.INPUT;
_txt.multiline = true;
ta.addChild(_txt);
}
protected function cbSize_changeHandler(event:ListEvent):void
{
fontFormatChanged();
}
protected function cbFont_changeHandler(event:ListEvent):void
{
fontFormatChanged();
}
protected function colorPicker_changeHandler(event:ColorPickerEvent):void
{
fontFormatChanged();
}
private function fontFormatChanged():void{
var tf:TextFormat = _txt.defaultTextFormat;
tf.size = cbSize.selectedLabel;
tf.font = cbFont.selectedLabel;
tf.color = colorPicker.selectedColor;
_txt.defaultTextFormat = tf;
_txt.setTextFormat(tf);
}
]]>
</mx:Script>
<mx:ComboBox id="cbSize" dataProvider="{sizeList}"
change="cbSize_changeHandler(event)" />
<mx:ComboBox id="cbFont" dataProvider="{fontList}"
change="cbFont_changeHandler(event)" />
<mx:ColorPicker id="colorPicker" change="colorPicker_changeHandler(event)" />
<mx:UIComponent id="ta" />
</mx:Application>
※ 引述《s00390 (Ally)》之銘言:
: 目前做的是 影片字幕
: 字幕我是用XML匯入FLASH
: 在SWF檔裡 可以任選字的顏色或者是大小和字型
: mFLV.addEventListener(MetadataEvent.CUE_POINT,readFLV);
: function readFLV(e:MetadataEvent):void
: {
: word_txt.text = e.info.name;
: font_cb.dataProvider = new DataProvider(
: ["Arial", "Courier New", "Times New Roman"]
: );
: size_cb.dataProvider = new DataProvider(
: [12,16,20,24,30,36]
: );
: size_cb.selectedIndex = 1;
: size_cb.editable = true;
: size_cb.textField.restrict = "0-9";
: size_cb.textField.maxChars = 2;
: font_cb.addEventListener(Event.CHANGE, fontChange);
: size_cb.addEventListener(Event.CHANGE, fontChange);
: picker.addEventListener(Event.CHANGE, fontChange);
: function fontChange(e:Event):void {
: // var begin:int = word_txt.selectionBeginIndex;
: // var end:int = word_txt.selectionEndIndex;
: // if (begin>=word_txt.text.length || end==0) {
: // return;
: // }
: // var format:TextFormat;
: switch (e.target.name) {
: case 'font_cb' :
: //format = new TextFormat(font_cb.value);
: break;
: case 'size_cb' :
: word_txt.size = size_cb;
: //format = new TextFormat(null, size_cb.value);
: break;
: case 'picker' :
: word_txt.textColor = picker.selectedColor;
: //format = new TextFormat(null, null, picker.selectedColor);
: }
: // word_txt.setTextFormat(format, begin, end);
: //showHtmlText(null);
: }
: word_txt.alwaysShowSelection = true;
: 主要是要改
: switch (e.target.name) {
: case 'font_cb' :
: //format = new TextFormat(font_cb.value);
: break;
: case 'size_cb' :
: word_txt.size = size_cb;
: //format = new TextFormat(null, size_cb.value);
: break;
: case 'picker' :
: word_txt.textColor = picker.selectedColor;
: //format = new TextFormat(null, null, picker.selectedColor);
: color的部分是已經改好的
: 註解//是代表之前的程式碼 之前的程式碼是要選取字 才能改變
: 想請問 font 字型 和 size 大小 那裏要改成什麼 才會向color那樣
: 不用選取 按一下他就會整個都改變 謝謝~~~~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.147.239.66