Tutorial 1: Simple Actions

This is a basic tutorial that shows how to create a 'quit button'

Step 1: Including the OneSprite Widget libraries:

Create a new movie and either attach the "OSW_behaviours", "OSW_Factories" and "OWS_Core" casts to your movie or import the contents to your movie (not all the scripts are required - see the section "Which Scripts are Required" [To come]).

Step 2: Create a placeholder bitmap

Second, create a simple blank cast member that is the size you want your widget to be. Give this bitmap a regPoint of (0,0). Note that some widgets have limits to how high or wide the widget can be, so the size you want may not be honoured. If you set the regPoint to (0,0), the widget will always be positioned correctly. Position this bitmap on stage at the location you want, then drag the "Widget.BevelButton" behaviour from the 'OWS_behaviours' cast on to the sprite.

Step 3. Configure the Widget

When you attached the behaviour, the GetPropertyDescriptionList dialog will appear. The following is the dialog for a bevel button:

Sample GPDL Sample GPDL

Change the 'label' to "Quit" and make a note of the 'event message' the widget will generate when it is clicked. Also, uncheck the "Broadcast Ready Message" option (in this example, the widget will only interact with another behaviour attached to the same sprite - so there is no need to notify other sprites of the creation of this button.

Step 4. Write an 'listener / action' for the behaviour

Widgets send their 'event messages' to objects that have added themselves to the widget's list of 'Listeners'. The simplest way to to do this is add a second behaviour to the widget like this:

-- Behaviour 'WidgetAction.HaltMovie'

on beginSprite (me)

  sendSprite(me.spriteNum, #AddListener, me)


on buttonClick (me)



This behaviour will add itself to the widgets listeners when the beginSprite event occurs. When the button is clicked, it will send a 'ButtonClick' message to this behaviour, when then halts the movie.

First published 09/06/2005