Dynamic Text File With Scroll

31 Oct

This post will cover bringing text into FlashMX dynamically.

In FlashMX, we can take a different approach. With the new, advanced scripting abilitites of Flash we can approach a much more precise and tidy method of coding and building an Flash application- centralised code. What this means is that in MX, you can have all of your code in one place in the movie, rather than scattered about the movie, making implementation of the movie easier and future updates of the movie much easier.

Lets take a look at the entire code-

This is very straighforward and uses the LoadVars() object to control the pace and progress of the movie. Firslty we assign a new LoadVars object which I called tmp. Then I told it which textfile to load into the movie. Then comes the meat of the code- the ‘onLoad’ function. Basically, this is code that is executed when the tmp object is loaded. Its a function literal (a function that is executed ‘as is’, as oppose to being defined, then called later) that does a number of jobs. First, it creates an empty text field called ‘display’, then positions it on the stage. All those number in the creatTextField statement refer to-

createTextField("name", depth, xpos, ypos, width, height);

The function then goes on to assign the new ‘display’ textbox a number of attributes- the kind of thing that prior to MX would need to be set in the authoring environment itself. Then when its done all the formatting, it matches up the textfile variable (blah) with the flash variable (display).

_root.display.htmlText = _root.tmp.blah;

‘blah’ is the variable name in the text file. e.g. the textfile is laid out like so-

blah=this is my actual content

Note the fact that I had to refer to ‘display’ as htmlText- this is in order to make full use of the html abilities of dynamic text if I’d so desired. e.g. my file could have looked like-

blah=this is my actual content

Now that the textbox is built and is calling in the text nicely, we add the scrollbar. Again, we don’t need to build one, we simply need to call one- as a component.

_root.attachMovie("FScrollBarSymbol","scroller",2);

This tells the movie to attach an instance of the scrollbar component to the main timeline, give itself an instance name of ‘scroller’ and place itself on depth 2 (don’t be too concerned with these ‘depth’ things. I’ll write a separate tute at some point explaining them in more detail).

The rest of the code then formats the scrollbar to look like we need it to in terms of position, colour, size etc. And that’s it- our job’s done- an actionscript built dynamic text box that displays the content of a textfile and adds an auto-scroller if the text is long enough to require it.

3 Responses to “Dynamic Text File With Scroll”

  1. c32 July 2, 2005 at 17:01 #

    no examples or files to download?

  2. john March 14, 2006 at 20:06 #

    you are a star have been searching for days for this tutorial.
    nice one
    john

  3. donald March 21, 2006 at 00:37 #

    honestly, anyone have a fla for this one?

Comments are closed.