Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design

  • Print
  • + Share This
  • 💬 Discuss

The Cool JSFL Part

Now, let's run some JSFL commands from within the panel to dump the values of the varName and valueTxt components into the Output panel and save the contents of the Output panel to the path specified by the saveTo string (which is created by the createDestinationPath() function). To do this:

  1. Following the closing curly brace for the if/else statements, but before the closing curly brace for the saveTheVar() function, add the following code to create the string of content that will be saved into the .txt file. This line of code creates a variable named txtFileContent and assigns it a value. The value is comprised of the text that appears in the varName component, followed by an equals sign (=) operator, followed by the text that appears in the valueTxt component, and followed by an ampersand (&), which will terminate the variable in the .txt file. (All that in one line of code!)

  2. txtFileContent = varName.text + "=" + valueTxt.text + "&";
  3. The next four lines of code we write will run JSFL commands from within our completed panel. Running JSFL commands from within regular ActionScript requires the use of the MMExexcute() command. To start, we'll clear the contents of the Output panel to make sure that it's empty before we dump our own content into it.

  4. MMExecute("fl.outputPanel.clear();");
  5. Next, we'll trace the txtFileContent string we created a moment ago into the Output panel.

  6. MMExecute("fl.outputPanel.trace('"+txtFileContent+"')");
  7. Next, we'll save the contents of the Output panel. To so this, we'll call the OutputPanel.save() command and use the saveTo string we created earlier as the path. We'll also append the saveAs name to the path so Flash knows what to name the file upon saving it. Finally, we append the ".txt" file extension to the string.

  8. MMExecute("fl.outputPanel.save('file:///"+saveTo+"/"+saveAs.text+".txt');");
  9. Finally, we'll clear the Output panel once again, because there's no compelling reason to display the saved content.

  10. MMExecute("fl.outputPanel.clear();");

TIP

If it's difficult to tell where all the quotation marks and apostrophes go, you can simply copy and paste the code above in your project.

All we need to do now is tell the Save button to run the saveTheVar() function, publish the panel, and test it out. Accessing the Output panel through JSFL can be done only from within the Flash authoring environment. To test the panel, we cannot simply run a test movie—we have to put the panel into the install directory and open it.

To finish up:

  1. Still on frame 1 of the actions layer, add the following code to run the saveTheVar() function from the saveBtn:

  2. saveBtn.onRelease = function (){
      saveTheVar();
    }
  3. Save your work.

  4. Open the Publish Settings dialog box. In the Formats tab, click the folder icon to the right of the row named Flash to open the Select Publish Destination dialog box. Browse to the WindowSWF folder in your Flash install directory (inside the Configuration folder for your user account) and choose it.

  5. Uncheck HTML because we don't need to create an .html page for our panel, click Publish, and click OK to exit the dialog box.

  6. Restart Flash (this is necessary the first time you add an .swf file to the WindowSWF folder).

  7. Choose Window > Other Panels > External Var Creator to open our new panel, as shown in Figure 4.

Figure 4Figure 4 A cool new panel that uses JSFL to save a name=value pair to an external .txt file.

If you've followed along and done everything according to my instructions, you should now have a working panel. Enter a variable name, enter some text for the value of the variable, choose your operating system, enter your user name for your operating system, and click the Save the Variable button. You should see the Output panel pop open, but it will be empty. Although this may seem strange, we told it to do this. We told it to clear its contents, display the txtFileContent string, save it, and clear itself again. Unfortunately, there's no way to then tell the panel to close.

Now for the best part: go look at your desktop. You should see a shiny new .txt file there. It was created and saved from your panel via the magic of JSFL.

Until next time, happy Flashing!

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus