|
|||
Lesson 1 - buttons and names Getting started with SuperCard can be a little harder than, say, getting started with Microsoft Word. This is because of what SuperCard can do rather than any failing on the part of the developers. SuperCard's PDF manuals are widely regarded as examples of some of the best documentation around, but new users can still feel a little lost - the manuals are superb for using SuperCard, but they can feel a little light on getting people started in the first place. There is a tutorial, and parts of the User Guide help people understand the general syntax of the language, but there needs to be a little more in the way of 'absolute beginner's guides'. What you need are some reasonably simple examples to dissect, and some simple tasks to attempt and customise. Here's a very simple example to get you started. Briefly: A SuperCard project consists of one or more windows. Each window will contain one or more cards. To keep things simple for now, stick to using just one window. And at first, stick to using just one card until you have a specific need for more. Right? Oh, sorry - didn't mean to bore anyone ;-) I'm going to presume you're using SuperCard 4 and the standard Runtime Editor. There are reasons why you might want to use SuperEdit or one of the alternative editors, but that can wait. Fire up SuperCard. Make a new project from the File menu. You'll be asked to save it right away. You'll automatically be given a single window with a single card, 320 pixels wide by 240 pixels high. You should have the main Tools palettes already open; if it isn't then choose this from the Tools menu. Now you have a naked project with no items on your card. Choose the round rectangle button tool from the Tools Palette (top-left item in the Buttons section) and draw a button somewhere on the card. You can option-click with this tool to create a default-sized button automatically. Now choose Object Info from the Edit menu. This opens the Info dialog for the selected object, in this case the button. As you can see, it isn’t named yet, although the ‘ShowName’ option is checked. This means that when you do give it a name it will be shown in the button. Notice that it does have an ID number (100, if this is the first button you’ve made in this card) and a number. You can refer to this button in a number of ways, which is useful to remember later on when you are writing scripts. You can say: card button "Save" or card button 1 or card button ID 100 Of course, you can't actually refer to THIS button by name, as it doesn't have one yet. To name it, just click in the Name field in the Button Info window and type. For this exercise type the number "1", and then press Return or Enter. Yes, I know it is also card button 1 (that is, number 1), but this is different - this is the name. As long as the "ShowName" option in the Button Info was left checked the name will be shown centered in the button. You can change the alignment to left or right if you like, although this usually looks odd. Now we will put a reasonably simple script into this button by opening its script window and typing a simple instruction. You can get into the script window for an object in a couple of ways. If the Info window is open just click the Script button. Otherwise, switch to the Browse tool (that’s the pointing hand tool at the top of the Tools palette), then point at the object and hold down the command and option keys (Apple and alt). Our script will get the button to change its name when it is clicked. It is currently called "1", so we will ask it to change the name to "2". The simplest script for this would be: on mouseUp You can test this right now. If you haven’t done so already, choose the Browse tool from the Tools palette. Now click the button you just made. It should change its name from "1" to "2". The problem with this script is that it is effectively a single-shot one. Once the name is changed there's no point in clicking it again. (Even though the script still operates, it just blindly changes the name from "2" to "2".) To make a more flexible script, we'll tell the button to change its name to whatever its name is plus 1. Now, that previous sentence isn't real script, but the logic and even the structure is surprisingly close to what we need. The "mouseUp" handler is the identifying wrapper for the lump of script which tells SuperCard what action is the script trigger. This is already typed for you in every button item, so when you open the button's Script Editor window all you need to do is type the line of script inbetween the "on mouseUp" and "end mouseUp" lines. Remember our pseudo script? Like I said, it is pretty close to the final article: CONCEPT: change its name to whatever its name is plus 1 SCRIPT: set the name of me to the short name of me + 1 So the final script is: on mouseUp We can simply refer to the button as "me" because the script is operating from within the button itself. The reason we have to say "the short name of me" rather than "the name of me" is because the 'name' of an item includes the decription of the object type, while the 'short name' is just the name itself. (When the script attempts to use maths to add 1 to whatever the name is, it has to have a simple number to use, not a string of numbers and letters.) For example: the name of me = card button "1" the short name of me = 1 The button's name will now keep increasing by 1 every time it is clicked. To make it reset itself when it reaches 10 you'll have to stick in a simple line of script to check the button's name and change it to "1" if it has reached 10. So here’s the plan: if the button's name is "10" then change the name to "1". CONCEPT: if the button's name is "10" then change the name of the button to "1" SCRIPT: if the short name of me is "10" then set the name of me to "1" on mouseUp
|
||||
Looking for exchange hosting? Choose from the best in Microsoft Exchange Hosting or get business email. Help your business grow with exchange hosting. |
||||