Articles Archive
Articles Search
Director Wiki
 

Flash-Lingo integration

December 12, 1999
by Pat McClellan

Dear Multimedia Handyman,

Could you tell me the simple way to join between Flash and Director using button/icon?

Let's say I'm doing some animation with Flash and save it in shockwave format (*.swf) and then put it in the Director cast. What is the script so that when I click in certain area in that Shockwave Flash then it will go to certain frame or movie.

Asyraq

Dear Asyraq,

There are several easy steps involved in getting Flash to work with Lingo. Step one is accomplished in the process of creating your Flash movie. Create a Flash movie which is just big enough for your purposes. For this example, I'll use the VCR buttons which are in Flash's button library. I drag them onto the stage and space them evenly.

Next we need to assign an action to each of the buttons. Remember, we're still working in the Flash application. Right click (or on the Mac, control-click) one of the buttons and select Properties...

Click on the Actions tab, and then select GetURL from the pulldown menu. (I don't know why they chose this term; it's not very intuitive, but that's the way it works.) Now we have some choices to make about what to enter as the GetURL parameter.

There are three different ways that we can send a message from the Flash movie to Director:

  1. pass a string
  2. specify an event (call a Lingo handler)
  3. make a Lingo statement directly

The simplest way is to enter a word or phrase which Director will accept as a string of characters. You could use the name of a frame or movie, or in this example I used the name of the button. Just for clarity, I used "buttonPlay" as the name of the button, rather than just "play" because "play" is a Lingo keyword. It would actually be OK to use "play" as a string -- it wouldn't confuse Lingo, but it might confuse me.

Assign GetURL actions to each of the other buttons, specifying the respective button names, then export the single frame Flash movie as a *.swf file. Now switch over to Director.

In Director, import the *.swf file into the cast. It will create a single cast member which can be scaled, rotated, etc. And since Flash uses vectors, this cast member will be tiny... only 6K for the entire set of VCR controls, irrespective of the size on the stage. Drag the Flash member onto the stage and adjust the size and position as needed. In this case, I applied Background Transparent ink, but it's actually better for performance if you can use Copy Ink. So, you might want to match the background color before saving the movie in Flash.

Sample movies (and the necessary Flash files) are available for download in Mac or PC format. These are D7 movies.

The buttons in the Flash member will send a string message when they're pressed. But we need a Lingo behavior to accept and process that message. Remember that the message coming from the Flash member is a "getURL" message? That's the name of the handler we'll need to write in Lingo. Here's the behavior to attach to the VCR buttons sprite.

on getURL me, flashString 
  -- do whatever with the flashString
  member("display").text = flashString
end getURL

There's only one handler in the behavior: getURL. The button's name gets passed to the handler as a parameter which I've called flashString. Inside the getURL handler you can do anything you want with the string. In this case, I simply put the string into a field member called "display". As another example, let's say that you want the button to take you to a specific frame of the movie. In the Flash movie, you'd enter the name of the frame as the getURL parameter. Then, in the Director getURL behavior, you'd do this:

on getURL me, flashString 
  go to frame flashString
end getURL

Other Options

I mentioned above that there are two other ways to pass a message in the getURL Action. Let's look at those now.

In this example, I created a separate Flash movie for each of the Flash buttons which are moving you from frame to frame in the Director movie. There are no behaviors on the Flash sprites at all. Instead, all of the Lingo has been entered when the Flash movie was created. In Flash, when you select a button and open the Properties menu, select GetURL for the action and specify that you're making a Lingo statement. Enter something like the following:

lingo: go to frame "pageTwo"

Now, all of the Lingo intelligence is preprogrammed in Flash. You simply import the flash movies and drag them to the stage. Sound like the easiest way, right? Well, it's easy but I don't really favor this method. The problem is that you don't have control when you're in Director. What if you change the names of the frames you're going to? Using this approach, you'd have to go back to the Flash application and change the Lingo there. Plus, Flash doesn't have a syntax checker for your Lingo. In general, I think it's a bad idea to script your Lingo in Flash.

Now let's look at the third approach, which is kind of a compromise between the first two we've examined. This approach is called "specifying an event"... which simply means calling a Lingo handler and providing parameter data. It will require a custom behavior on the sprite in Director, which will receive the handler call and process the data.

In this example, I created a single Flash movie with the three color buttons. Like before, I assign a GetURL action to each button. But in this example, I enter:

event: processColor "red"

When I import the color buttons as a single Flash cast member in Director (only 2.7K), I place it on the stage and attach the following behavior.

on processColor me, whichColor
  put whichColor
  case whichColor of
    "red": newColor = rgb(255,0,0)
    "yellow": newColor = rgb(255,204,0)
    "green": newColor = rgb(0,153,0)
  end case
  
  sprite(2).color = newColor
  
end processColor

This behavior receives the call to the processColor handler and converts the color name from a string to the rgb value. I've set it up to display the color in sprite channel 2. You can see how you could create custom handlers to do anything when triggered by a Flash member.

Don't Forget

Flash members can add a lot of style to your Director movie, which economizing on the file size. Using the three methods demonstrated above, you'll be able to make the Flash members interact fluently with Lingo. But don't forget... if you're distributing your movie as a projector, you'll need to include the Flash Asset Xtra with the program. (This isn't necessary for Shockwave.)

Good luck with your program.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

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