tlengnick
asked on
Flash CS5 Textfield
The following code creates a textfield and imports text from a text document to fill the textfield.
Then, when the playhead hits frame 30, it triggers the 2nd part of the code to replace the text.
All that works.
However, when I navigate back to frame 1, it's creating a new textfield on top of the old one (which is what my code tells it to do).
However, I just want it to create the textfield once, then on all subsequent visits to frame 1, just replace the text like it does in frame 30.
Any ideas?
Start AS3======================= =======
var TextURL:String;
//Setup Text Box to load external text file
var myTextLoader:URLLoader = new URLLoader();
var myText:TextField = new TextField();
TextURL = "text/introduction.txt";
myTextLoader.load(new URLRequest(TextURL));
myTextLoader.addEventListe ner(Event. COMPLETE, onLoaded);
function onLoaded(e:Event):void
{
myText.text = e.target.data;
addChild(myText);
addChild(mySb);
}
//THE FOLLOWING CODE SITS ON FRAME 30
TextURL = "text/texture.txt";
myTextLoader.load(new URLRequest(TextURL));
END AS3======================= ===
Then, when the playhead hits frame 30, it triggers the 2nd part of the code to replace the text.
All that works.
However, when I navigate back to frame 1, it's creating a new textfield on top of the old one (which is what my code tells it to do).
However, I just want it to create the textfield once, then on all subsequent visits to frame 1, just replace the text like it does in frame 30.
Any ideas?
Start AS3=======================
var TextURL:String;
//Setup Text Box to load external text file
var myTextLoader:URLLoader = new URLLoader();
var myText:TextField = new TextField();
TextURL = "text/introduction.txt";
myTextLoader.load(new URLRequest(TextURL));
myTextLoader.addEventListe
function onLoaded(e:Event):void
{
myText.text = e.target.data;
addChild(myText);
addChild(mySb);
}
//THE FOLLOWING CODE SITS ON FRAME 30
TextURL = "text/texture.txt";
myTextLoader.load(new URLRequest(TextURL));
END AS3=======================
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, CyanBlue - not sure why I didn't think of a function that initializes everything at once...still learning, I guess.
Thanks to both of you - very helpful!
Thanks to both of you - very helpful!
ASKER
I ended up doing just what you suggested (see code below). Is there anything I could do differently that would be "cleaner" (less overhead)?
START AS3================
//Format Text
var myFormat:TextFormat = new TextFormat();
if (myText)
{
trace("Doing nothing because there's already a textfield");
}
else
{
var myText:TextField = new TextField();
myText.visible = false;
mySb.visible = false;
txtBG_mc_i.visible = false;
}