Think of something that you wish Authorware could do but it doesn't?  Let the our good friends at Macromedia know via the wishlist.

Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed.

Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list.

Back

B7002 - How can I dynamically track the location of a button [includes more on property lists!]

by - Joseph Ganci


Is there a way to use a function like DisplayX or DisplayY for an Authorware-created button hanging off an interaction icon?

I have a map icon hanging off an interaction icon called "Find..." and want to capture the placed XY coords . I am using DisplayX@"Find..." DisplayY@"Find..." and then telling my MSAgent to move to those coordinates. When I query the values for DisplayX and DisplayY I get 0 for both.

Its the only icon in my flowline called "Find...". When I open the properties for the button, I can see the X&Y values, but I'd rather capture it with an AW variable instead so I don't have to hard code it everytime.


A button is a response type. Instead of DisplayX and DisplayY, which work with Display and Interaction icons, for instance, use the Response variables: ResponseLeft, ResponseTop, etc. Voilą!

Thanks... ResponseLeft, ResponseWidth, etc. were the variables I was looking for! Gosh, sometimes I still feel like such a newbie.

Now, since the text for the button is set by the name of the button (which is the icon name), what if I want another button to have the same name elsewhere? That would require naming the icon the same, right? ...and that would conflict with a "ResponseWidth@"Button" statement since there would be two buttons of the same name. There's not a way to set the name of an icon to a variable is there? What about having the text of the button being different than the icon name? Am I missing something obvious?


Glad they helped. On to your next question.

I rarely use direct links to icons, because I usually am leading a team environment where I'm writing a template and letting others on my team create the content code. (Nowadays, though, I have team members who also can and do create templates, woo-hoo!) What happens is team members need to copy and paste code into new template files and often this means they lose their links and end up with the dreaded "ResponseLeft@DeleteIcon" problem. Even when I'm working on a file by myself, I don't like to use direct links because of this problem.

To avoid that problem, and to start to answer your question, I usually create a Calc icon at the top of my file which contains all my links in variables, as well as commented copies. So if I have three buttons, Go, Stop, and Dance, I may have a Calc icon that shows:

  Button_Go := @"Go"
  Button_Stop := @"Stop"
  Button_Dance := @"Dance"

  --Button_Go := @"Go"
  --Button_Stop := @"Stop"
  --Button_Dance := @"Dance"

The commented copies are an insurance policy. If by chance links get broken within this Calc icon, the comments will not change and will remind me of where the link was supposed to be so I can recreate the top lines correctly. Of course, I also take care to name my variable links something that makes sense. This means that instead of using

  ResponseLeft@"Go"

I use

  ResponseLeft@Button_Go

Now, I've written the above to illustrate my method but it's not exactly what I normally do. I normally use a property list instead of separate variables, but I didn't want to scare away those of you for whom the thought of using a property list is still the reason you use a night light in your bedroom.

Using a property list is similar but is a little easier to use:

  Buttons := [:]
  Buttons[#Go] := "Go"
  Buttons[#Stop] := "Stop"
  Buttons[#Dance] := "Dance"

  --Buttons[#Go] := "Go"
  --Buttons[#Stop] := "Stop"
  --Buttons[#Dance] := "Dance"

So when I want to use a link I use

  ResponseLeft@Buttons[#Go]

What's the point of this? Well, I started by wanting to talk about how you can refer to icons indirectly, without using a direct link. We haven't really done that yet, we've simply moved where the direct links are happening from their previous locations, interspersed throughout your file, to one Calc icon at the top of your file. This is invaluable for many reasons, but doesn't quite get us where you need to go yet.

What if you have two buttons, both called "Go"? If that's the case, you'll have a problem because Authorware will complain when you try to set up the link that there is more than one icon called "Go".

Oh, no, what to do? In cases like this, a little organization can really help. For instance, let's say you have three Interactions that all use buttons called Go, Stop, Dance. If you put these buttons in the same order for each Interaction and call the three Interactions "Inter1", "Inter2", and "Inter3", you can set up the links as follows:

  Interactions := [:]
  Interactions[#Inter1] := @"Inter1"
  Interactions[#Inter2] := @"Inter2"
  Interactions[#Inter3] := @"Inter3"

  --Interactions[#Inter1] := @"Inter1"
  --Interactions[#Inter2] := @"Inter2"
  --Interactions[#Inter3] := @"Inter3"

Then you can use indirection, pointing to the children of the three interactions for what you need:

  ResponseLeft@ChildNumToID(Interactions[#Inter1], 1)

would point to the Go button attached to the Interaction called "Inter1". To point to the Go button attached to "Inter2", just change #Inter1 to #Inter2 above. To point to the Stop button for the third interaction, you can use:

  ResponseLeft@ChildNumToID(Interactions[#Inter3], 2)

and to point to the Dance button for the second interaction, you'd use:

  ResponseLeft@ChildNumToID(Interactions[#Inter2], 3)

If this is a little too cryptic, you can set up a set of constants in another property list at the top of your file. These are not links, just substitutions, so you don't have to use a commented copy since they're not going to lose their values.

  Buttons[#Go] := 1
  Buttons[#Stop] := 2
  buttons[#Dance] := 3

Then you can use

  ResponseLeft@ChildNumToID(Interactions[#Inter2], Buttons[#Dance])

which is a little easier to read than our last example.

You may also want to consider setting up a subroutine for those buttons with the same name if it makes sense to do so in your design.

There are 0 reviews
Add your review
Back