dimanche 20 novembre 2016

Change font family and font size in ActionScript 3

I am trying to embed text into Flash using XML and Action Script 3. I found the code that works for me, but I don't know how to change Font and Font Size in Action Script.

Can you help me? Thank you!

My AS3 fie looks like this:

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; 
}
}

And XML File looks like:

<?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>

Aucun commentaire:

Enregistrer un commentaire