<HTML>
<HEAD>
<TITLE>DirectAnimation SDK, JScript sample</TITLE>
<SCRIPT LANGUAGE="JScript">
<!--
if (window.top.frames.length!=0 && window.top.frames[0].ShowNoButtons!=null)
    window.top.frames[0].ShowNoButtons();
//-->
</SCRIPT>
</HEAD>

<BODY BGCOLOR=Black TOPMARGIN=15 LEFTMARGIN=20 ONRESIZE="SetSize()">
<INPUT TYPE=Button Value="Speed Up" ONCLICK="SpeedUp()">
<INPUT TYPE=Button Value="Slow Down" ONCLICK="SlowDown()"><BR>
<FONT COLOR=Blue FACE="Verdana, Arial, Helvetica" SIZE=8>
I bounce in the browser window even if you resize it!<p>
I bounce in the browser window even if you resize it!<p>
I bounce in the browser window even if you resize it!<p>
I bounce in the browser window even if you resize it!<p>
</FONT>

<DIV ID=flowText STYLE="position:absolute; width:30; height:30">
<FONT SIZE=6 FACE="Arial,Tahoma,Verdana" color=Yellow>
Hi
</FONT></DIV>
          
<OBJECT ID="DAControl"
  STYLE="position:absolute; width:40; height:40; z-index:-1"
  CLASSID="CLSID:B6FFC24C-7E13-11D0-9B47-00C04FC2F51D">
</OBJECT>

<!--USE COMMENT TAGS FOR SCRIPTING-->
<SCRIPT LANGUAGE="JScript">
<!--
    m = DAControl.MeterLibrary;

    // The values of width and height are updated each time the window
    // is resized.
    width = m.ModifiableBehavior(m.DANumber(document.body.clientWidth-30));
    height = m.ModifiableBehavior(m.DANumber(document.body.clientHeight-30));

    function SetSize() {
        width.SwitchTo(m.DANumber(document.body.clientWidth-30));
        height.SwitchTo(m.DANumber(document.body.clientHeight-30));
    }

    function SpeedUp() {
        speed *= 2;
        speedAnim.SwitchTo(m.DANumber(speed));
    }

    function SlowDown() {
        speed *= 0.5;
        speedAnim.SwitchTo(m.DANumber(speed));
    }

    // SpeedAnim is a ModifiableBehavior that changes its value when
    // either of the buttons is pressed.
    speed = 100;
    speedAnim = m.ModifiableBehavior(m.DANumber(speed));
    pos = m.Integral(speedAnim.RunOnce());

    // Keep x between 0 and width, y between 0 and height.
    x = new ActiveXObject("DirectAnimation.DANumber");
    x.Init(m.Until(pos, m.Predicate(m.GTE(pos, width)),
                   m.Until(m.Sub(width, pos), m.Predicate(m.GTE(pos, width)), x)));
    y = new ActiveXObject("DirectAnimation.DANumber");
    y.Init(m.Until(pos, m.Predicate(m.GTE(pos, height)),
                   m.Until(m.Sub(height, pos), m.Predicate(m.GTE(pos, height)), y)));

    // Use the x and y to animate the position of the "flowText" control.
    myPoint = m.Point2Anim(x, y);
    myPoint = myPoint.AnimateControlPosition("flowText", "JScript", 0, 0.02);
    DAControl.AddBehaviorToRun(myPoint);

    DAControl.Start();
//-->
</SCRIPT>
</BODY>
</HTML>
