Learning Flash: LoadVars() - ActionScript

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Scrolling Dynamically Loaded Text

Free Flash Tutorial


Step 7    <<   Previous      Intro   1   2   3   4   5   6   7   8   9  10   11   12     Next   >>       >>   Webwasp Mates

 

Step Seven: LoadVars() - ActionScript

  1. Create a new Layer above your Scroll Button Down layer by clicking on the Insert Layer Button:
  2. Rename the layer to: Actions
  3. If the Actions panel is closed, open it: Window > Development Panels > Actions (F9)
  4. Place the following ActionScript in frame 1 of the Actions layer:

    //strict-typed variables to be used later in the movie.
    var scrollDirection:String;
    var scrollBarMax:Number = _root.scrollDown._y - _root.scrollTrackbar._y - _root.scrollTrackbar._height

    //creates a new loadVars object that will load the text
    var myLV:LoadVars = new LoadVars();
    myLV.onLoad =
    function(success) {
        
    if (success) {
            loadedInfo
    .htmlText = myLV.info;
            
    _root.loadedInfo.scroll = 1;
            
    _root.scrollTrackbar.scrollBar._y = 0;
            scrollCheck();
        }
    else {
            loadedInfo.text =
    "There has been an error loading the requested information. Please contact the Webmaster and report your error.";
        }
    };

    //automatically starts the loading of "page1.txt" when the movie loads
    myLV
    .load("page1.txt");

ActionScript Explained:
var scrollBarMax:Number = _root.scrollDown._y - _root.scrollTrackbar._y - _root.scrollTrackbar._height
This line determines how far the scroll Bar can move down before touching the scroll down button.

myLV.onLoad = function(success) {
This line defines a function to be called when the handler onLoad is called. Whenever any called text file is completely downloaded from the server and ready to be imported into the movie, this line will call the following function, passing the Boolean variable "success" to indicate whether the text file was found and of the correct type.

loadedInfo.htmlText = myLV.info;
This sets the text in the loadedInfo text box to the text in the text file with the variable name "info". The property htmlText specifies that the text to be imported should be formatted for any html tags.

_root.loadedInfo.scroll = 1;
_root.scrollTrackbar.scrollBar._y = 0;

_root.loadedInfo.mouseWheelEnabled = false
This line will reset the scroll property of the text box and also reset the position of the scroll Bar. The scroll property will be explained in detail later.

scrollCheck();
This line runs the function scrollCheck() which will be later defined. The scrollCheck() function will test to see if the text file is long enough to need scrolling.

loadedInfo.text = "There has been an error loading the requested information. Please contact the Webmaster and report your error."
If the success value from the onLoad handler is returned false, then the text file was either corrupted or was not found. It is always a good idea to put a message just in case an error like this occurs.

         

Step 7    <<   Previous      Intro   1   2   3   4   5   6   7   8   9  10   11   12     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

49528 visitors to this page since Sept 05 •

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.