Load parameters from a text file to Flash animation using loadVariables() function.
Text file must be in the format:
Load text file by using:
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:
- Create a folder and download t1012.txt file to the folder (right click on the link and choose Save Target As)
- Launch Alligator Flash Designer and choose “Blank document”.
- Choose “Frame” > “Frame Size” to set movie size to 300 x 200.
- Choose “Frame” > “ActionScript” and paste the following code:loadVariables("t1012.txt");
- Choose “Edit Field” tool and draw 2 edit fields.
- Choose “Select” tool. Double click each edit field and change “Variable name” to “Edit1” and to “Edit2” respectively.
- Choose “Button” tool and draw a button below edit fields.
- Choose “Select” tool. Select the button. Choose Action > OnUp. Select “actionscript” and enter the code:Edit1 = param1;
Edit2 = param2;
- Choose Frame > Frame Delay and check Stop at this frame, click OK
- Choose “File” > “Export SWF file” and export the file to the same folder where t1012.txt file is located.
- 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.