Hi! I’ve searched and was unable to find a solution to this (probably very simple) problem I’m having.
I’m loading an XML file and looping through it to generate movie clips for each of the main nodes. Each node has some text, which I would like to show in a dynamically created movie clip for each.
The XML looks pretty much like this, only with more “piece” nodes:
<portfolio>
<piece>
<image>portfolio/02.jpg</image>
<name>two</name>
</piece>
</portfolio>
And this is the relevant AS3 code so far (portfolio is the name of a MC on the stage):
function xmlLoaded(e:Event):void {
var loadedxml:XML = new XML(e.target.data);
for (var i:uint=0; i<loadedxml.piece.length(); i++)
{
var pieceholder:MovieClip = new MovieClip();
portfolio.addChild(pieceholder);
var pieceloader = new Loader();
var pictURLReq:URLRequest = new URLRequest(loadedxml.piece.image.text()*);
pieceholder.addChild(pieceloader);
pieceloader.load(pictURLReq);
words = loadedxml.piece.name.text()*;
trace ("words is " + words);
var text_image:TextField = new TextField();
pieceholder.addChild(text_image);
text_image.addChild(words);
}
}
The images load with no problem, and the trace for the “words” seems to work. At that point (after the trace) I get an error:
ReferenceError: Error #1069: Property addChild not found on flash.text.TextField and there is no default value.
at test_fla::MainTimeline/xmlLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I know there are fancy ways to get dynamic text to look good, by embedding the font and making your own style, etc., but I’ll cross that bridge when I get to it… Right now I’d be happy if I could get the text to show up at all!
Thanks!!