AS3 - Add scroll bar to dynamically generated text field? - actionscript-3

I'm new to actionscript 3, so please forgive me.
I am loading a text file into my flash file and then dynamically creating a text field which will take in the myBody text from that file. The problem is that the text in myBody could be very long, so I would like to add a scroll bar when needed to the dynamically generated text field. Is there any way to this?
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
var myTextField_txt:TextField = new TextField();
myTextField_txt.multiline = true;
myTextField_txt.wordWrap = true;
myTextField_txt.border = true;
myTextField_txt.height = 100;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
myTextField_txt.text = e.target.data.myBody;
addChild(myTextField_txt);
}
myTextLoader.load(new URLRequest("mySampleFile.txt"));

Related

How do I format different lines of text differently, from a textfield created in AS3, with text populated from a txt file?

So I have a flash file in AS3, latest version of flash.
It creates a text box in AS3. It then uses AS3 to grab text from a text file (2 lines) and loads it in. I then used further code to format the text size, font, color etc.
But NOW...I need line 1 of the text box to be a certain format (large, caps) and the second line to be a different format (smaller, no caps)
Here is all my code below:
//BEGIN TXT LOADER
var myTextLoader:URLLoader = new URLLoader();
var winnerText:TextField = new TextField();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
winnerText.text = e.target.data;
addChild(winnerText);
}
myTextLoader.load(new URLRequest("EditableText.txt"));
//BEGIN TEXT BOX FORMATTING
winnerText.width = 1920;
winnerText.height = 300;
winnerText.y = 430;
//BEGIN TEXT & FONT FORMATTING
var casinoBranding:TextFormat = new TextFormat();
casinoBranding.size = 90;
casinoBranding.align = TextFormatAlign.CENTER;
casinoBranding.font = "Bliss Pro";
casinoBranding.leading = -50;
winnerText.defaultTextFormat = casinoBranding;
You can apply a TextFormat like #Aaron suggests. Another way of doing is to use stylesheets. Here is an example
http://snipplr.com/view/39474/as3-textfield-and-stylesheet-example-created-in-actionscript/
You can apply a TextFormat to a specific range of text using TextField/setTextFormat().
To apply a different text format to the first line of text you can do this:
var casinoBranding:TextFormat = new TextFormat();
var casinoBrandingFirstLine:TextFormat = new TextFormat();
// ... apply formatting options
function onLoaded(e:Event):void {
winnerText.defaultTextFormat = casinoBranding;
winnerText.text = e.target.data;
winnerText.setTextFormat(casinoBrandingFirstLine, 0, winnerText.getLineOffset(1));
}
Note that if word wrapping is involved it changes what the "first line" really means.

Clearing content from a movieclip in a blank keyframe in AS3

var loader:URLLoader;
var allWords:Array;
var thisWord:String;
var textContainer:MovieClip;
var textFields:Array;
var textStyle:TextFormat;
var underline:MovieClip;
var numCorrect:uint;
var totalLetters:uint;
var misses:uint;
var missesToLose:uint;
function initializeGame():void
{
loader = new URLLoader();
allWords = new Array();
textContainer = new MovieClip();
textFields = new Array();
textStyle = new TextFormat();
textStyle.font = "Courier New";
textStyle.size = 48;
textStyle.bold = true;
Hi All,
I have created this game and only added the beginning portion of the code. The entire code would be tedious to go through. I want to click a button and go to a clear keyframe, however when I test the movie the underline movieclip still shows. How can I clear the frame completely, do I have to removeChild for the movieclip? How do I do that? Is there a way to completely unload the SWF for this game after it is loaded? If so what code can I use?
Thanks

how to load text file into flash using AS3?

How to load text file into flash using AS3 . and the text file not on the root but on my server on the internet
There are already a few posts about this.
Here are 2 examples: Flash AS3 Read Text File
and Working with txt file on as3
What part, specifically, are you stuck on?
UPDATE:
var url:String = "http://concept-vs.com/load/my_text_file.txt";
var loader:URLLoader = new URLLoader(new URLRequest(url));
loader.addEventListener(Event.COMPLETE, onFileLoaded);
function onFileLoaded(e:Event):void
{
var loader:URLLoader = e.target as URLLoader;
var text:String = loader.data; // variable text now holds the text from the file
}

AlivePDF not writing out text using addText(). Nothign I'm trying is working. What am I missing?

No matter what I try I can't write anything to a PDF that can be seen, although the text is there when viewing the resultant PDF in Notepad. What am I not doing? Here's a code snippet. the variable tf is a TextField defined in the class. This works in the SWF, just not with PDF.
private function onButtonClick(e:MouseEvent):void {
tf.text = "Hey, you clicked the button!";
myPDF = new PDF(Orientation.PORTRAIT, Unit.INCHES, Size.A4);
myPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE)
myPDF.addPage();
myPDF.addText(tf.text, 20, 20 );
var filename:String = "Test-file.pdf";
var f:FileStream = new FileStream();
var file:File = File.userDirectory.resolvePath(filename);
f.open(file, FileMode.WRITE);
var bytes:ByteArray = myPDF.save(Method.LOCAL);
f.writeBytes(bytes);
f.close();
}

Display XML content in Flash movie as Text

Inside a Flash Movie (Actionscript 3) I need to display the content of a XML file.
I am passing the url of the file as a parameter. So I am using the following:
var file : XML;
var url = loaderInfo.parameters.url;
var loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(url));
function onLoadComplete(e:Event){
file = new XML(e.target.data);
} // OnLoadComplete
How can I display the entire content of the XML file, as text, in the Flash Movie?
Probably the content will be big so I would like to have scroll bars.
Thank You,
Miguel
try this for example.
//... previous code
loader.load(new URLRequest(url));
var myTextBox:TextField = new TextField();
myTextBox.width = 200;
myTextBox.height = 150;
myTextBox.multiline = true;
myTextBox.wordWrap = true;
myTextBox.background = true;
myTextBox.border = true;
addChild(myTextBox);
function onLoadComplete(e:Event){
file = new XML(e.target.data);
myTextBox.text = file.toString();
}