【发布时间】:2015-05-18 17:22:58
【问题描述】:
我有一个带有滚动条的主时间线。子时间线包含一个带有按钮的长字符串。我正在使用 localToGlobal 来确定按钮在舞台上的位置,因此我可以在按钮的左侧或右侧弹出相关信息,具体取决于弹出窗口可能落在舞台上的位置。一切似乎都正常工作,直到滚动条移动时间线太多,然后跟踪的 x 值似乎返回随机值。 关于如何获得 x 值的一致结果的任何想法,它只显示我在舞台上单击的位置,所以如果它太靠近左边缘,我可以告诉弹出框向右走,如果太靠近右边缘,我可以告诉它向左走?我已经布置好了结构,它只是主舞台上的 x 值似乎很不稳定。
这是时间轴上的 AS。
stop();
import flash.events.MouseEvent;
import flash.geom.Point;
//attach listeners to all your buttons
btn19980930.addEventListener(MouseEvent.CLICK, showPopup);
btn20110928.addEventListener(MouseEvent.CLICK, showPopup);
btn20111214.addEventListener(MouseEvent.CLICK, showPopup);
btn20120110.addEventListener(MouseEvent.CLICK, showPopup);
//define space in the timeline movie clip
var leftEdge:Number=360;
function showPopup(evt:MouseEvent){
//figure out which button got clicked
var buttonClicked = evt.currentTarget;
//first get the local position of the button
var localPoint:Point = new Point(buttonClicked.x, buttonClicked.y);
//then calculate the buttons position in the global space
var buttonGlobalPoint:Point = buttonClicked.localToGlobal(localPoint);
trace(localPoint);
trace(buttonGlobalPoint);
if (buttonGlobalPoint.x < leftEdge){
gotoAndStop(buttonClicked.name + "_right");
} else {
gotoAndStop(buttonClicked.name + "_left");
}
}
【问题讨论】:
-
根据研究调查 hitTestObject,但仍然没有回答为什么 localToGlobal 在处理滚动时不喜欢工作
标签: actionscript-3 flash