Articles Archive
Articles Search
Director Wiki
 

Pointing the Finger at Flash Buttons

June 12, 2001
by Will Turnage

Dear Multimedia Handyman,

I was wondering how to retain the cursor from a Flash file that I have embedded into Director so that when I roll over something in the Flash file, it changes to the finger and when I roll out it goes back to the arrow pointer. Any ideas would be great. Thank you in advance.

Rich

Rich,

While it's very convenient to use Flash movies inside of Director, the thing you have to keep in mind is that Director is still running the show. A Flash movie inside Director is just another sprite in Director's score, so Director's not capable of just flipping a switch and letting Flash take over the cursors in the Director movie. But that doesn't mean you can't change the cursor when you rollover a Flash button.

The key to doing this is to take advantage of Flash's ability to communicate with Director. In order for Flash to communicate with Director, you have to use the getURL command inside of Flash. However, instead of specifying a URL or a Javascript command, you need to specify a single line of Lingo code or call a handler. To execute a single line of Lingo using getURL in Flash, just type lingofollowed by a single line of Lingo code.

Check out this sample code attached to a button inside a Flash movie:

on (rollOver) {
  getURL ("lingo:cursor 280");
}

on (rollOut) {
  getURL ("lingo:cursor 0");
}

on (release) {
  getURL ("lingo:alert(\"you clicked on blue\")");
}

By starting your getURL command with Lingo:, the remaining text gets sent straight to Director, which then processes the command. In this example, when you roll over the Flash button, it tells Director to set the cursor to 280 -- the pointing finger. When you roll out from the Flash button, Flash tells Director to reset the cursor to 0 -- the default arrow. Finally, when you click on the Flash button, it tells Director to display an alert box telling you that you've clicked on blue.

But what if you need to execute more than one line of Lingo code when you roll over a button? It would be pretty cumbersome to keep writing line after line of getURL statements executing one line of Lingo at a time. In these instances, you should use event in your getURL statements instead of lingo.

When you use event, it calls a Director handler instead of executing pure Lingo. More specifically, it calls a handler found in a behavior attached to the Flash sprite inside Director. To use event in a getURL statement, type event followed by the name of the handler to execute. To pass along parameters to your handler, you just need to include the parameters after the handler name, and make sure that they are separated by commas.

Check out this sample code attached to a button inside a Flash movie:

on (release) {
  getURL ("event: FlashMouseUp, \"blueButton\"");
}

on (rollOver) {
  getURL ("event: FlashMouseEnter, \"blueButton\"");
}

on (rollOut) {
  getURL ("event: FlashMouseLeave, \"blueButton\"");
}

When you roll over, roll off of, or click and release on this Flash button, a user-defined event is generated inside Director and parameters are sent that include the name of the button. So in the first example, when you click on the Flash button, it would call the FlashMouseUp handler inside a behavior attached to the Flash sprite in Director.

On the Director side, the code is just as simple. For instance, you might have a behavior attached to the Flash sprite in your Director movie that contains this code:

on FlashmouseEnter me, whichButton
  member ("buttonMessages").text = "You rolled over button " & QUOTE & whichButton & QUOTE
  cursor 280
end

on FlashMouseLeave me, whichButton
  member ("buttonMessages").text = "You rolledout from button "
& QUOTE & whichButton & QUOTE
  cursor
0
end

on FlashMouseUp me, whichButton
  member ("buttonMessages").text = "You clicked on button "
& QUOTE & whichButton & QUOTE
end
 

In each one of these Director handlers, the cursor is set if appropriate, and some text is placed into a field on screen that tells the user what is going on in the Flash movie.

Here's a sample movie that demonstrates a Flash movie using lingo and event to execute Lingo statements and handlers in Director.

You'll notice that in the final product, there's really not much difference between using event and lingo for simple cursor changes. So when should you use lingo and when should you use event? The answer really depends on your specific project. The bottom line is that using event gives you much more control within Director, so if you're creating a large Director project it would probably be smarter to use it. That way, if you need to change some code related to the Flash button, you can do it in your Director project instead of opening up the raw FLA file, making the changes there, and then reimporting the SWF file into Director. But if your project is mostly Flash-based, and you don't really have a lot of Director code, then it might just be simpler to use lingo in your getURL statements.

A sample Director 8 and Flash 5 file are available for download in Windows or Macintosh format. The Flash SWF file imported into Director was saved in a Flash 4-compatible format from Flash 5.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.