Edit: what inquiesco said
Right click on Object types (under Projects) and choose Insert new object
Double click 'Function'
Click on "Add event" in the event sheet
Double click on Function
Double click on "On function"
Type MyFunction between the quotes and click Done
You now have a function called "MyFunction"
To add code to it:
Click on "Add Action" on the event sheet next to Function | On "MyFunction"
Add any normal actions
You can also add sub events under the "Function | On "MyFunction" event