0
votes

I have created a simple animated screen show that imports 7 different text values from a xml document that the client can edit each week.

The code I'm using in flash is below code:

var xmlData:XML = new XML();
var theURL_ur:URLRequest = new URLRequest("ClientText.xml");
var loader_ul:URLLoader = new URLLoader(theURL_ur);
loader_ul.addEventListener("complete", fileLoaded);

function fileLoaded(e:Event):void
{
   xmlData = XML(loader_ul.data);

   m_txt.text = xmlData.monday;
   tu_txt.text = xmlData.tuesday;
   w_txt.text = xmlData.wednesday;
   th_txt.text = xmlData.thursday;
   f_txt.text = xmlData.friday;   
}

Ive placed this code on frame 1 of my action layer and added 7 separate dynamic text boxes labelled with its corresponding instance name on layer 2.

Upon export all works as it should, populating all 7 text box with its designated text within the linked xml doc.

The problem I'm having is unless all the text boxes are on frame 1 they do not display.

Im trying to display text box1 (m_txt) on frame 20, then display text box2 (tu_txt) on frame 40, then text box3 (w_txt) on 60....and so on.

Apologies as this is a real noob question as this is all new to me. Any help would be extremely appreciated.

Cheers all

1
You can not set the text of a text field unless it's available. So you can : set the text for all your text fields in the 1st frame and then you can hide/show the appropriate text field according the the current frame, or save your data and use it when you are in the appropriate frame to set to the text field text ... - akmozo

1 Answers

0
votes

As already stated, you can't set the text (or any property) of a textfield (or any object) that doesn't exist yet. So you can just leave them on frame 1 (or wherever you put your XML loading script) and hide them, or store the XML as you currently do with xmlData and assign the text on the frames that those text fields appear.

Or you could wrap this stuff in a symbol:

  • Store your XML in a variable as you currently do with xmlData.
  • Create a symbol, call it something like XMLTextLoader. It should contain a single dynamic TextField with a name such as textField.
  • Place instances of this XMLTextLoader symbol wherever you want them. Give them instance names that map to the XML data they will display, such as text_monday and text_tuesday.
  • On frame 1 of the XMLTextLoader symbol (or in a class linked to the symbol) you can use the name to determine what XML data to display:

var xmlName:String = this.name.split("_")[1]; // Ex: "text_monday" => "monday"
var xml:XML = parent.xmlData[xmlName];
this.textField.text = xml;

Now you have a re-usable component-like symbol that can placed anywhere and it will handle displaying the text from the XML. It won't require additional timeline code and if you move them around it will still work.

If you need dramatically different text styling (ie a single dynamic TextField can't be used to represent all the text) you can put the code in an external class file, such as XMLTextLoader.as, and create multiple symbols of the same structure and set them all to have their "base class" set to XMLTextLoader.as in the library.