I have hard a lot about the ability to use ActiveX elements in Director, but so far I haven't had much luck. How do I use them? Are there any considerations I should keep in mind with ActiveX?
ActiveX is a powerful component that can add some great functionality to Director but it is a double edged sword. Here are the basic pros and cons...
Pros
-Wide variety of components that can be dropped directly in to Director
-Many components are free
-The ability to download and install components from inside the application if the user does not already have them
Cons
-Only supported on the PC
-Not supported in Shockwave
-Some calls are not supported in Director
-Limited documentation for Macromedia
So you may be asking "Is it worth it to use ActiveX?" The answer to this will of course depend on your project, but if you are making applications for the PC then you can add some great functionality to your projects very easily. In the behavior database there are a number of pre-built behaviors for various ActiveX elements to get you started such as the Internet Explorer and Adobe Acrobat controls. This is a great way to imbed a browser or PDF files directly into Director to seamlessly integrate these common types of documents into your project. So what do you need to get started?
Well, first the user will need ActiveX installed on their machine as well as the specific control you are planning to use. This isn't a very big problem as ActiveX is installed with all Microsoft operating systems since Windows 95 (version B) as well as Internet Explorer 4 and above. The controls can either be installed with a standard installer, or using the web from inside Director. It is a good idea to check for all of this in your start movie. Below is a simple script that will check for ActiveX and the particular element you need to use and return a list of the results. To get the ID of an ActiveX element, open it in Director, click the URL button and then click copy to copy the ID string. As an example, the web browser control for Internet explorer would be checked like this...
put checkActiveX("{8856F961-340A-11D0-A96B-00C04FD705A2}")
--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
on checkActiveX whatControl
set theList= []
if ActiveXInstalled() = -1 then
add theList, 1
else
add theList, 0
end if
if ActiveXControlQuery(whatControl) = -1 then
add theList, 1
else
add theList, 0
end if
return theList
end
on getBehaviorDescription me
return "This script verifies the presence of ActiveX and the presence of the specified ActiveX control. To get the control ID, open the ActiveX element, click the URL button and then click copy."
end
Now that we have verified that all components are properly installed we can move on to the "guts" of the control. For this example we will use a fairly simple control. This is the PopupMenu Object control that is installed with Internet Explorer. This gives the effect of a toolbar "fly out" from right clicking in windows and returns the result of the click.
Lets start with inserting the ActiveX element. Go to Insert>Control>ActiveX in the top toolbar. From here we can select the ActiveX element we want to use. Using the search feature we choose the PopupMenu Object control and choose "OK."
(Exhibit 1)
Now that we have the element lets examine its parts. We can access 3 types of parameters in an ActiveX element; properties, methods, and events. Properties are much like properties in a behavior. They can be tested and some can be set. Methods are handlers that can be run in the ActiveX element, and elements are handlers the element itself runs and the values it returns. Lets look at these pieces for the control we chose.
(Exhibit 2)
We can use the addItem method to add items to the list. This is called in the following format...
addItem(sprite 1, "itemName")
All methods use this format, but in Director 7 you can also use dot syntax like so...
sprite(1).addItem("itemName")
The advantage of this is that some commands that are shared with lingo work in dot syntax mode that do not in regular lingo format. For example, an ActiveX element may have a method called "play". Lingo also has a "play" command an will try to run its version before the element. Using dot syntax we send the command directly to the sprite, allowing the ActiveX element to run its "play" command instead.
Now we can test the itemCount property like so...
put the itemCount of sprite 1
or
put sprite(1).itemCount
Ok. Now we can set the items and use the popUp method to open the box. Calling the popUp command with its 2 required parameters will open our popup menu. Since we want it to open relative to the mouse location, we set the location values to -10000, -10000. Since this is off screen it will open the box in relative to the mouse. Next we want to get the results of the user's click. Using the "click" event we see that the ActiveX returns an integer of which item was clicked. One thing to keep in mind is that using an ActiveX element's events is a great way to keep up with the data, but the "me" parameter in lingo will not work. One way around this is to simply set a global variable when you run the command and then use this in the callback. Below is the example code.
--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
property spriteNum, itemList, doItem
global tempSprite
on getPropertyDescriptionList me
p_list = [:]
if the currentSpriteNum > 0 then
if sprite(the currentSpriteNum).member.type = #ActiveX then
p_list.addProp(#itemList, [#format : #string, #default : "Choice1,Choice2,Choice3", #comment : "List of options separated by a comma, and no spaces."])
p_list.addProp(#doItem, [#format : #string, #comment : "Name of handler to run with the results", #default : "alert"])
else
alert "This behavior only works on ActiveX elements."
end if
end if
return p_list
end
on beginSprite me
if sprite(spriteNum).member.type = #ActiveX then
the itemDelimiter =","
repeat with x = 1 to itemList.item.count
sprite(spriteNum).addItem(itemList.item[x])
end repeat
end if
end
on popup me
sprite(spriteNum).popup(-10000, -10000)
end
on click whatItem
do (sprite(tempSprite).doItem & "(" & quote & sprite(tempSprite).itemList.item[whatItem] & quote & ")")
end
on getBehaviorDescription me
return "This behavior works with the PopupMenu Object ActiveX element included with Microsoft Internet Explorer. The first parameter is the list of options separated by a comma. the second is the name of the handler to process the event."
end
Now that you have the basics try a few ActiveX elements on your own. You'll be amazed at what you can add to Director with a few clicks. Happy coding
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA