日期:2014-03-16  浏览次数:20678 次


我们可以使用 PUBLIC:METHOD 元素来定义 HTC 的方法集,如下例所示:

<PUBLIC:METHOD NAME="startFlying" />

当我们定义了一个方法后,我们就可以在 HTC 中直接来调用它。请看下面的例子:

<PUBLIC:METHOD NAME="tick" />
<PUBLIC:METHOD NAME="startFlying" />
:
<SCRIPT LANGUAGE="JScript">
var currCount;
var flyCount;
var flying;
var msecs;

var oTop, oLeft;
msecs = 50;
flyCount = 20;
flying = false;

runtimeStyle.position = "relative";
runtimeStyle.visibility = "hidden";

window.attachEvent("onload", onload);

function onload()
{
// delay commences from the window.onLoad event
if (delay != "none")
{
window.setTimeout(uniqueID+".tick()", delay);
}
}

function tick()
{
if (flying == false)
{
startFlying();
}
else
{
doFly();
}
}

function startFlying()
{
if (fromX==null && fromY==null)
{
if (from=="top")
{
runtimeStyle.posTop = -offsetTop-offsetHeight;
}
else if (from=="bottom")
{
runtimeStyle.posTop = element.document.body.clientHeight;
}
else if (from=="right" )
{
runtimeStyle.posLeft = element.document.body.clientWidth;
}
else
{
runtimeStyle.posLeft = -offsetLeft-offsetWidth;
}
}
else
{
runtimeStyle.posTop = fromY;
runtimeStyle.posLeft = fromX;
}

runtimeStyle.visibility = "visible";
flying = true;

oTop = runtimeStyle.posTop;
oLeft = runtimeStyle.posLeft;

currCount = 0;
doFly();
}

function doFly()
{
var dt, dl;

currCount++;
dt = oTop / flyCount;
dl = oLeft / flyCount;

runtimeStyle.posTop -= dt;
runtimeStyle.posLeft -= dl;

if (currCount < flyCount)
{
window.setTimeout(uniqueID+".tick();", msecs);
}
else
{
runtimeStyle.posTop = 0;
runtimeStyle.posLeft = 0;
flying = false;
evObj = createEventObject();
evObj.setAttribute("resulty", uniqueID);
finished.fire(evObj);
}
}
</SCRIPT>