A Hello World tutorial
Last edit by:
Softpress Support
3 Aug, 2009
Pages in this section:
- A Hello World tutorial
- Action Elements
- Class FWAction
- Class FWActionList
- Class FWAttribute
- Class FWColor
- Class FWLinkParameter
- Class FWListData
- Class FWOSAInterpreter
- Class FWOutput
- Class FWPage
- Class FWParameter
- Class FWParameterList
- Class FWTag
- Files and Freeway Actions
- Organisation of Classes
- Specific Properties and User Methods
- Weaver
Output “Hello World!” to your Freeway page
Actions are text files that contain a mixture of XML and JavaScript. The only tool for the job (other than Freeway Pro) is a good text editor, we recommend using one of the following:
- TextWrangler (BareBones Software) - Free
- TextMate (MacroMates) - €50 (approx. $70)
- BBEdit (BareBones Software) - $125
Note, TextEdit can do the job too but you must make sure you are working in plain text mode. To convert a TextEdit document to plain text press Command-Shift-t.
To create an Action that outputs the text “Hello world!” in an item, do the following:
Create a new text document in your chosen text editor. Define the type of Action you want (a standalone Action in this case) by typing the following on the page:
<action>
</action>
All the Action code will be placed inside this element but first we need to give the Action a unique name and a title:
<action name="helloWorld" title="Hello World!">
The name is used internally by Freeway, in a real world situation you should make sure it’s unique by adding something specific to you to the name, we use this for example:
name="com.softpress.actions.helloWorld"
Save the file in the following location with the filename helloWorld.fwaction:
Home/Library/Application Support/Freeway 5/Actions/
Open Freeway, if it isn’t open already, and create a new document. Go to the Insert menu and then to Action Item, near the bottom of the list you should see your Hello World! Action. It won’t do anything yet but select to add the Action to the page. Let’s add something to the page then!
Add content using Actions is done using JavaScript, this tutorial isn’t going to teach you any JavaScript, so we recommend learning more about it at w3schools. Add the following to your Action:
<action name="helloWorld" title="Hello World!">
<action-javascript>
function fwBeforeEndBody()
{
}
</action-javascript>
</action>
The
The Action has access to all the elements that have been created in the page so far (up until the point just before the closing body tag is created). To place our text inside the item the Action is applied to, we need to find the item in the tag tree. Add the following:
<action name="helloWorld" title="Hello World!">
<action-javascript>
function fwBeforeEndBody()
{
var ourItem = fwDocument.fwTags.fwFind("", fwItem);
var pTag = ourItem.fwAdd("p", true);
pTag.fwAddRaw("Hello World!");
}
</action-javascript>
</action>
The code above finds the item the Action is applied to and stores it in the ourItem variable. To do this it uses the fwFind(tag[,item]) function to look for the first occurrence of a tag inside the fwItem (which is the code for the item the Action is applied to).
Once found we generate a new paragraph tag by using the fwAdd(tag[,closingTag]) function and store it in the variable pTag. This text “Hello World!” is then added as raw text to the tag by using the fwAddRaw(string) function.
