Selteco.com > FlashDesignerZONE.com > Tutorials > T1012

Load parameters from a text file to Flash animation using loadVariables() function.

Text file must be in the format:

param1=value1&param2=value2

t1012.txt

set variables

Load text file by using:

loadVariables("t1012.txt");

Usually in Frame’s ActionScript.

Create 2 edit fields for param1 and param2. Name fields Edit1 and Edit2. Create “Set Variables” button. Use the following ActionScript code for button’s OnUp (or OnClick) event:

Edit1 = param1;Edit2 = param2;

To complete the tutorial:

  1. Create a folder and download t1012.txt file to the folder (right click on the link and choose Save Target As)
  2. Launch Alligator Flash Designer and choose “Blank document”.
  3. Choose “Frame” > “Frame Size” to set movie size to 300 x 200.
  4. Choose “Frame” > “ActionScript” and paste the following code:loadVariables("t1012.txt");
  5. Choose “Edit Field” tool and draw 2 edit fields.
  6. Choose “Select” tool. Double click each edit field and change “Variable name” to “Edit1” and to “Edit2” respectively.
  7. Choose “Button” tool and draw a button below edit fields.
  8. Choose “Select” tool. Select the button. Choose Action > OnUp. Select “actionscript” and enter the code:Edit1 = param1;
    Edit2 = param2;

    Click OK.

  9. Choose Frame > Frame Delay and check Stop at this frame, click OK
  10. Choose “File” > “Export SWF file” and export the file to the same folder where t1012.txt file is located.
  11. Choose “File” > “Export Web Page” and click OK for default options, a page with Flash animation should pop up in a new browser window. Click the button to load variables into edit fields.

The script will not work in preview mode unless you put txt file in the temp folder.

get flash