I am creating a XML driven thumbnail gallery. Which works fine with this code:
Code:import fl.transitions.Tween; import fl.transitions.easing.*; var fadeTween:Tween; var imageText:TextField = new TextField(); var imageLoader:Loader; var xml:XML; var xmlList:XMLList; var xmlLoader:URLLoader = new URLLoader(); xmlLoader.load(new URLRequest("data.xml")); xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded); function xmlLoaded(event:Event):void { xml = XML(event.target.data); xmlList = xml.children(); for(var i:int = 0; i < xmlList.length(); i++) { imageLoader = new Loader(); imageLoader.load(new URLRequest(xmlList[i].attribute("thumb"))); imageLoader.x = 25; imageLoader.y = i * 200 + 25; imageLoader.name = xmlList[i].attribute("source"); addChild(imageLoader); imageLoader.addEventListener(MouseEvent.CLICK, showPicture); } } function showPicture(event:MouseEvent):void { imageLoader = new Loader(); imageLoader.load(new URLRequest(event.target.name)); imageLoader.x = 250; imageLoader.y = stage.stageHeight / 4; addChild(imageLoader); imageText.x = imageLoader.x + 200; imageText.y = 600; for(var j:int = 0; j < xmlList.length(); j++) { if(xmlList[j].attribute("source") == event.target.name) { imageText.text = xmlList[j]; } } fadeTween = new Tween(imageLoader, "alpha",None.easeNone,0,1,1,true); } imageText.autoSize = TextFieldAutoSize.LEFT; addChild(imageText);
What my problem is, is I am trying to format the text in the dynamically created text field by doing this:
And the text doesn't format, what am I doing wrong?Code:import fl.transitions.Tween; import fl.transitions.easing.*; var fadeTween:Tween; var imageText:TextField = new TextField(); var myFormat:TextFormat = new TextFormat(); myFormat.font = "Helvetica"; myFormat.color = "0xFF0000"; myFormat.bold = true; myFormat.size = 25; myFormat.kerning = 2; var imageLoader:Loader; var xml:XML; var xmlList:XMLList; var xmlLoader:URLLoader = new URLLoader(); xmlLoader.load(new URLRequest("data.xml")); xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded); function xmlLoaded(event:Event):void { xml = XML(event.target.data); xmlList = xml.children(); for(var i:int = 0; i < xmlList.length(); i++) { imageLoader = new Loader(); imageLoader.load(new URLRequest(xmlList[i].attribute("thumb"))); imageLoader.x = 25; imageLoader.y = i * 200 + 25; imageLoader.name = xmlList[i].attribute("source"); addChild(imageLoader); imageLoader.addEventListener(MouseEvent.CLICK, showPicture); } } function showPicture(event:MouseEvent):void { imageLoader = new Loader(); imageLoader.load(new URLRequest(event.target.name)); imageLoader.x = 250; imageLoader.y = stage.stageHeight / 4; addChild(imageLoader); imageText.x = imageLoader.x + 200; imageText.y = 600; for(var j:int = 0; j < xmlList.length(); j++) { if(xmlList[j].attribute("source") == event.target.name) { imageText.text = xmlList[j]; } } fadeTween = new Tween(imageLoader, "alpha",None.easeNone,0,1,1,true); } imageText.autoSize = TextFieldAutoSize.LEFT; addChild(imageText); imageText.setTextFormat(myFormat);




Reply With Quote