With the multimedia controls available in Internet Explorer 4.0 and higher, it's a snap to add a little pizzazz to your Active Server applications. One control, the Structured Graphics control, which was introduced in Internet Explorer 4.0, uses simple vector primitives to create 3-D graphics that you can rotate, scale, and fill. Because the Structured Graphics control is an ActiveX control and because it requires Internet Explorer 4.0 or higher, you'll need to use browser detection in your application to make sure the client can use the control. That being said, let's take a look at the powerful--and fun--Structured Graphics control. In this article, we'll show you how to use it to create simple text animation without any graphics images.
Figure A: It's easy to create text animation with the new
multimedia controls in Internet Explorer 4.0 and beyond.
Warning: Be aware that while both Internet Explorer 4.0 and 5.0 use the DirectAnimation Sequencer control, each implements it slightly differently. As a result, if you use earlier versions of this control, the exact syntax will differ from our examples; though, the basic concepts and methods still apply. |
If your InterDev Toolbox doesn't display either of these controls, right-click on the Toolbox and select Customize Toolbox from the shortcut menu. Visual InterDev displays the dialog box shown in Figure B.
Figure B: You can find the StructuredGraphics and Sequencer
controls under the Microsoft DirectAnimation controls section in the
Customize Toolbox dialog box.
Next, click on the ActiveX Controls tab and select the Microsoft DirectAnimation StructuredGraphics and Sequencer controls. Click OK to add them to the Toolbox.
Now, open a new HTML page in a Visual InterDev 6.0 project and name it Graphics.html. Next, select the Source tab and drag the Structured Graphics control from the ActiveX portion of the toolbar. Drop it anywhere between the two <BODY> tags. If InterDev displays the control as a square box, right-click on it and select Always Show As Text from the resulting shortcut menu. Now set its ID to ZDJ, so we can refer to it by its name. At this point, the <OBJECT> code should look like the following:
<OBJECT classid="clsid:369303C2-D7AC
=>-11D0-89D5-00A0C90833E6" id="ZDJ"
style="LEFT: 0px; TOP: 0px" VIEWASTEXT>
<PARAM NAME="SourceURL" VALUE="">
<PARAM NAME="CoordinateSystem" VALUE="0">
<PARAM NAME="MouseEventsEnabled" VALUE="0">
<PARAM NAME="HighQuality" VALUE="0">
<PARAM NAME="PreserveAspectRatio"
VALUE="-1">
</OBJECT>
We'll modify the style definition next. To do so, change the
control's <OBJECT> tag as follows: <OBJECT classid="clsid:369303C2-D7AC-11D0
=>-89D5-00A0C90833E6" id="ZDJ"
style="POSITION:ABSOLUTE; HEIGHT: 350;
=>WIDTH: 500; ZINDEX: 1" VIEWASTEXT>
As you can see, we added style definition attributes to the control
to more precisely manage its position on the page. Now we need to add more
parameters to our control so it will display the text. To do so, add the
following lines of code before the </OBJECT> tag: <PARAM NAME="Line0001"
VALUE="SetLineStyle(1)">
<PARAM NAME="Line0002"
VALUE="SetLineColor(0, 0, 255)">
<PARAM NAME="Line0003"
VALUE="SetFillStyle(1)">
<PARAM NAME="Line0004" VALUE="SetFont
=>('Bertram', 100, 100, 0, 0, 0)">
<PARAM NAME="Line0005" VALUE="Text
=>('ZDJ', -125, -100, 0)">
Notice that for each parameter we set attributes for the text, and
that in the last parameter we define the actual text value. We also set
the value for the x, y, and z coordinates for the
text's position. The coordinates 0, 0, 0 represent the control's exact
center. At this stage, feel free to experiment with the text colors and
fonts.
Using similar steps, insert two more instances of the control for the rest of our text, Active and Server. Set the ID fields for the controls to Active and Server, respectively. Since we want each line of text to appear under the previous one and to overlap, you'll need to change the x and y coordinate values as well. At this point, the page's Design view in Visual InterDev should look similar to Figure C.
Figure C: We added three Structured Graphic controls to our
page.
Tip: To add multiple lines of text within the same
Structured Graphics control, simply add additional Text
<PARAM> tags to a single object. For example, we could have
used the following code: Doing so would combine all three text lines in the same
object. |
We've finished our implementation of the Structured Graphics control. Next, we'll add the Sequencer control to define the animation and timing sequence.
<OBJECT id="TCG" CLASSID="clsid:B0A6BAE2
=>-AAF0-11D0-A152-00A0C908DB96"
STYLE="WIDTH:2;HEIGHT:2">
</OBJECT>
TCG.Item("Action1").AT 0.00, _
"ScriptName", -1, 0.050
The first AT parameter represents the start time formatted in
seconds.tenths. The value defines how long the sequencer should wait
before invoking the action after the sequencer begins playing. Since we
want the animation to begin immediately after the page loads, we set this
value to 0.00.
The next value contains a string value indicating the script we want to run--in this case, we'll replace ScriptName with the Structured Graphics control's Rotate() method. (We'll explain this method in more detail later.) In addition to calling a method, you can also pass any parameters along with it.
The next parameter indicates the number of times the action will repeat. We used -1, which causes the action to repeat infinitely. The final setting represents the time between repetitions. In our example, this value helps control the rotation speed. (Using zero would cause the control to render the text as fast as possible.) At this point, we're ready to examine the rotate method for our first Structured Graphics control.
TCG.Item("Action1").AT 0.00, _
"Active.Rotate(0,0,5)", -1
To complete the sequence for the other text objects, add one more
action that invokes the rotate method, such as: TCG.Item("Action1").AT 0.00, _
"Server.Rotate(1,0,0)", -1
So far, we've added three lines of text using the Structured
Graphics control and added timing sequence with the Multimedia Sequencer
control. Now we're ready to complete the script to invoke the animation.
<SCRIPT LANGUAGE="VBScript">
Sub window_onload()
msgbox ("triggered")
TCG.Item("Action1").AT 0.00, _
"Active.Rotate(0,0,5)", -1
TCG.Item("Action1").AT 0.00, _
"Server.Rotate(1,0,0)", -1
TCG.Item("Action1").Play
end sub
</SCRIPT>
Add this script to the head of your page to complete the animation
code. Finally, save Graphics.htm. Listing A shows the complete page
definition. To preview the page, either select the Quick View tab, or
right-click on the page and choose View In Browser. When the page opens in
Internet Explorer, notice how the bottom two lines of text move gracefully
along precise angles to complete the animation. Wow! Animation without any
graphics!
Listing A: The Graphics.htm page
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE="VBScript">
Sub Window_Onload()
TCG.Item("Action1").AT 0.00, "Active.Rotate(0,0,5)", -1
TCG.Item("Action1").AT 0.00, "Server.Rotate(1,0,0)", -1
TCG.Item("Action1").Play
End Sub
</SCRIPT>
</HEAD>
<BODY>
<OBJECT classid="clsid:369303C2-D7AC-11D0-89D5-00A0C90833E6"
id="ZDJ" STYLE="HEIGHT: 350px; POSITION:absolute;
=>WIDTH: 500px; ZINDEX: 1" VIEWASTEXT>
<PARAM NAME="Line0001" VALUE="SetLineStyle(1,0)">
<PARAM NAME="Line0002" VALUE="SetLineColor(0,0,255)">
<PARAM NAME="Line0003" VALUE="SetFillStyle(1)">
<PARAM NAME="Line0004" VALUE="SetFont('Bertram',100,100,0,0,0)">
<PARAM NAME="Line0005" VALUE="Text('ZDJ',-175,-100)">
</OBJECT>
<OBJECT classid="clsid:369303C2-D7AC-11D0-89D5-00A0C90833E6"
id="Active" STYLE="HEIGHT: 350px; POSITION: absolute;
=>WIDTH:500px; ZINDEX: 1" VIEWASTEXT>
<PARAM NAME="Line0001" VALUE="SetLineStyle(1,0)">
<PARAM NAME="Line0002" VALUE="SetLineColor(0,0,255)">
<PARAM NAME="Line0003" VALUE="SetFillStyle(1)">
<PARAM NAME="Line0004" VALUE="SetFont('Verdona',100,100,0,0,0)">
<PARAM NAME="Line0005" VALUE="Text('Active',-215,-30)">
</OBJECT>
<OBJECT classid="clsid:369303C2-D7AC-11D0-89D5-00A0C90833E6"
id="Server" STYLE="HEIGHT: 350px; POSITION: absolute;
=>WIDTH: 500px; ZINDEX: 1" VIEWASTEXT>
<PARAM NAME="Line0001" VALUE="SetLineStyle(1,0)">
<PARAM NAME="Line0002" VALUE="SetLineColor(0,0,255)">
<PARAM NAME="Line0003" VALUE="SetFillStyle(1)">
<PARAM NAME="Line0004" VALUE="SetFont('Verdona',100,100,0,0,0)">
<PARAM NAME="Line0005" VALUE="Text('Server',-225,45)">
</OBJECT>
<OBJECT classid="clsid:B0A6BAE2-AAF0-11D0-A152-00A0C908DB96"
id="TCG" STYLE="WIDTH:2;HEIGHT:2">
</OBJECT>
</BODY>
</HTML>
Copyright © 2000, ZD
Inc. All rights reserved. ZD Journals and the ZD Journals logo are trademarks of ZD
Inc. Reproduction in whole or in part in any form or medium without
express written permission of ZD Inc. is prohibited. All other product
names and logos are trademarks or registered trademarks of their
respective owners.