2016-11-20 181 views
0

我正在嘗試使用XML和動作腳本3將文本嵌入到Flash中。我發現代碼適用於我,但我不知道如何更改字體和字體大小操作腳本。在ActionScript 3中更改字體系列和字體大小

你能幫我嗎?謝謝!

我的AS3外商投資企業是這樣的:

var yPlacement:int = 20; 
var xPlacement:int = 30; 
var distance:int = 60; 
var myFormat:TextFormat = new TextFormat(); 
myFormat.color = 0xAA0000; 
myFormat.size = 24; 
myFormat.italic = true; 
myFormat.align = TextFormatAlign.CENTER 
var myXML:XML = new XML(); 
var XML_URL:String = "myXMLFile.xml"; 
var myXMLURL:URLRequest = new URLRequest(XML_URL); 
var myLoader:URLLoader = new URLLoader(myXMLURL); 
myLoader.addEventListener("complete", xmlLoaded); 
function xmlLoaded(event:Event):void { 
myXML = XML(myLoader.data); 
var xmlDoc:XMLDocument = new XMLDocument(); 
xmlDoc.ignoreWhite = true; 
var menuXML:XML = XML(myLoader.data); 
xmlDoc.parseXML(menuXML.toXMLString()); 
for each (var ListItem:XML in myXML..ListItem) { 
var listColor:String = ListItem.itemColor.toString(); 
var listLabel:String = ListItem.itemLabel.toString(); 
var listPhone:String = ListItem.itemPhone.toString(); 
var myText1:TextField = new TextField(); 
myText1.text = listLabel; 
myText1.autoSize = TextFieldAutoSize.LEFT; 
myText1.x = 2; 
myText1.y = 2; 
var myText2:TextField = new TextField(); 
myText2.text = listPhone; 
myText2.autoSize = TextFieldAutoSize.LEFT; 
myText2.x = 2; 
myText2.y = 20; 
var clip_mc = new MovieClip(); 
clip_mc.addChild(myText1); 
clip_mc.addChild(myText2); 
addChild(clip_mc); 
clip_mc.y = yPlacement; 
clip_mc.x = xPlacement; 
yPlacement = yPlacement + distance; 
} 
} 

和XML文件的樣子:

<?xml version="1.0" encoding="utf-8"?> 
<XML> 
<myXMLList> 
<ListItem> 
<itemColor>FFFFFF</itemColor> 
<itemLabel>NÃO ACORDES O DRAGÃO</itemLabel> 
<itemPhone>SÁBADO - 14H00</itemPhone> 
<itemSize>32</itemSize> 
</ListItem> 
<ListItem> 
<itemColor>FFE8E8</itemColor> 
<itemLabel>Emily Owen</itemLabel> 
<itemPhone>888-888-8888</itemPhone> 
</ListItem> 
<ListItem> 
<itemColor>DDFDB3</itemColor> 
<itemLabel>Jeff Jones</itemLabel> 
<itemPhone>666-666-6666</itemPhone> 
</ListItem> 
<ListItem> 
<itemColor>DDFDB3</itemColor> 
<itemLabel>Hello</itemLabel> 
<itemPhone>666-666-6666</itemPhone> 
</ListItem> 
</myXMLList> 
</XML> 

回答

1

我發現這個在這裏,但沒有測試: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d87.html

理論上,看起來像這樣(結合你的代碼和例子):

var myText1:TextField = new TextField(); 
myText1.text = listLabel; 
myText1.autoSize = TextFieldAutoSize.LEFT; 
myText1.x = 2; 
myText1.y = 2; 

var format1:TextFormat = new TextFormat(); 
format1.size= 14; 

var format2:TextFormat = new TextFormat(); 
format2.font = "Courier"; 

myText1.setTextFormat(format1); 
myText1.setTextFormat(format2); 
1

每次更改文本時,必須在更改文本後調用setTextFormat()方法。 確保如果要嵌入字體您有字體庫中的:

enter image description here

enter image description here

如果文本的變化,你不叫調用setTextFormat(參數...) TextFormat將被忽略。

此致敬禮。 Nicolas

+0

AS3指南參考:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/幾乎與PHP語言一樣清晰:https://secure.php.net/manual/en /index.php 即使AMO PHP參考更高效... – tatactic

+0

php.net充滿了評論和例子。 在Adobe網站上:「評論已被系統管理員禁用」。 S..t :( 在php.net上,你可能會發布例子,等等...... 這有時真的很有幫助 – tatactic

+0

我認爲這是Adobe選擇停止對未來的支持:( 即使他們繼續銷售Flash CC 這是一個可恥的AMO 他們知道閃存的未來,即使他們繼續銷售這種產品! – tatactic