Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3 localToGlobal返回看似随机的x值_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 AS3 localToGlobal返回看似随机的x值

Actionscript 3 AS3 localToGlobal返回看似随机的x值,actionscript-3,flash,Actionscript 3,Flash,我有一个带有滚动条的主时间线。子时间线包含一个以按钮为特征的长字符串。我使用localToGlobal来确定按钮在舞台上的位置,这样我就可以根据弹出按钮可能落在舞台上的位置,在按钮的左侧或右侧弹出相关信息。在滚动条将时间线移动得太多之前,一切似乎都正常,然后跟踪的x值似乎返回随机值。 关于如何得到一个x值的一致结果,只显示我在舞台上点击的位置,这样我就可以告诉弹出窗口,如果它太靠近左边缘,就向右,如果它太靠近右边缘,就向左,你知道吗?我已经安排好了结构,只是主舞台上的x值似乎不稳定 这是时间表上

我有一个带有滚动条的主时间线。子时间线包含一个以按钮为特征的长字符串。我使用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");
    }

}
stop();
导入flash.events.MouseEvent;
导入flash.geom.Point;
//将侦听器附加到所有按钮
btn19980930.addEventListener(MouseEvent.CLICK,showPopup);
btn20110928.addEventListener(MouseEvent.CLICK,showPopup);
btn20111214.addEventListener(MouseEvent.CLICK,showPopup);
BTN2011010.addEventListener(MouseEvent.CLICK,showPopup);
//在时间轴电影剪辑中定义空间
var leftEdge:Number=360;
功能显示弹出窗口(evt:MouseeEvent){
//找出哪个按钮被点击了
var buttonClicked=evt.currentTarget;
//首先获取按钮的本地位置
var localPoint:Point=新点(buttonClicked.x,buttonClicked.y);
//然后计算按钮在全局空间中的位置
var buttonGlobalPoint:Point=buttonClicked.localToGlobal(localPoint);
跟踪(本地点);
跟踪(按钮全局点);
if(按钮LobalPoint.x
您应该能够使用
stageX
stageY
获取鼠标事件的全局坐标:

var stageMousePoint:Point = new Point(evt.stageX, evt.stageY);

有一件事最终成功了,尽管它很凌乱,也很笨重,那就是复制每个按钮的脚本部分,以便能够为每个按钮提供不同的“leftEdge”参数,这样即使按钮的大小和锚定方式不同,它们也会对自定义数字做出反应。我知道可能有一种方法可以浓缩剧本,但我正在继续我所知道的

   // button 01
   //attach listeners to all your buttons
btn19980930.addEventListener(MouseEvent.CLICK, showPopup);

var leftEdge:Number=200;

function showPopup(evt:MouseEvent){
    //figure out which button got clicked
    //figure out which button got clicked
    var buttonClicked = evt.currentTarget;


    //first get the local position of the button
    var stageMousePoint:Point = new Point(buttonClicked.stageX, buttonClicked.stageY);

    //then calculate the buttons position in the global space
    var buttonGlobalPoint:Point = buttonClicked.localToGlobal(localPoint);

    //trace(localPoint);
    trace(buttonGlobalPoint);

    if (stageMousePoint.x < leftEdge){
        gotoAndStop(buttonClicked.name + "_right");
    } else { 
        gotoAndStop(buttonClicked.name + "_left");
    }

}

   // button 02
    //attach listeners to all your buttons
    btn19990224.addEventListener(MouseEvent.CLICK, showPopup);

    var leftEdge2:Number=215;

    function showPopup2(evt:MouseEvent){
        //figure out which button got clicked
        var buttonClicked2 = evt.currentTarget;

        //first get the local position of the button
        var localPoint2:Point = new Point(buttonClicked2.x, buttonClicked2.y);

        //then calculate the buttons position in the global space
        var buttonGlobalPoint2:Point = buttonClicked2.localToGlobal(localPoint2);

        //trace(localPoint);
        trace(buttonGlobalPoint2);

        if (buttonGlobalPoint2.x < leftEdge2){
            gotoAndStop(buttonClicked2.name + "_right");
        } else { 
            gotoAndStop(buttonClicked2.name + "_left");
        }

    }
//按钮01
//将侦听器附加到所有按钮
btn19980930.addEventListener(MouseEvent.CLICK,showPopup);
var leftEdge:编号=200;
功能显示弹出窗口(evt:MouseeEvent){
//找出哪个按钮被点击了
//找出哪个按钮被点击了
var buttonClicked=evt.currentTarget;
//首先获取按钮的本地位置
var stageMousePoint:Point=新点(buttonClicked.stageX,buttonClicked.stageY);
//然后计算按钮在全局空间中的位置
var buttonGlobalPoint:Point=buttonClicked.localToGlobal(localPoint);
//跟踪(本地点);
跟踪(按钮全局点);
if(stageMousePoint.x
更妙的是,卡丁暗示了正确的鼠标使用方向,但与其担心鼠标到底在哪里,我只需要知道鼠标是在屏幕的左侧还是右侧,在某个阈值内。我可以决定弹出窗口出现在哪一边

stop();

import flash.events.MouseEvent;
import flash.geom.Point;
import flash.display.MovieClip;
import flash.display.DisplayObject;

//attach listeners to all your buttons
btn19980930.addEventListener(MouseEvent.CLICK, showPopup);
btn19990224.addEventListener(MouseEvent.CLICK, showPopup);
btn20010105.addEventListener(MouseEvent.CLICK, showPopup);
btn20050702.addEventListener(MouseEvent.CLICK, showPopup);
btn20060000.addEventListener(MouseEvent.CLICK, showPopup);
btn20060629.addEventListener(MouseEvent.CLICK, showPopup);
btn200720080000.addEventListener(MouseEvent.CLICK, showPopup);
btn20080229.addEventListener(MouseEvent.CLICK, showPopup);
btn20090307.addEventListener(MouseEvent.CLICK, showPopup);
btn20091209.addEventListener(MouseEvent.CLICK, showPopup);
btn20101125.addEventListener(MouseEvent.CLICK, showPopup);
btn20110120.addEventListener(MouseEvent.CLICK, showPopup);
btn20110312.addEventListener(MouseEvent.CLICK, showPopup);
btn20110729.addEventListener(MouseEvent.CLICK, showPopup);
btn20110316.addEventListener(MouseEvent.CLICK, showPopup);
btn20110815.addEventListener(MouseEvent.CLICK, showPopup);
btn20110909.addEventListener(MouseEvent.CLICK, showPopup);
btn20110928.addEventListener(MouseEvent.CLICK, showPopup);
btn20111214.addEventListener(MouseEvent.CLICK, showPopup);
btn20120110.addEventListener(MouseEvent.CLICK, showPopup);

var initialX : Number = 496;

function showPopup(evt:MouseEvent){
    //figure out which button got clicked
    var buttonClicked = evt.currentTarget;

    // not finished, we need to calculate using timeline_mc x and width

    if (stage.mouseX <= 400){
        gotoAndStop(buttonClicked.name + "_right");
    } else { 
        gotoAndStop(buttonClicked.name + "_left");
    }

}
stop();
导入flash.events.MouseEvent;
导入flash.geom.Point;
导入flash.display.MovieClip;
导入flash.display.DisplayObject;
//将侦听器附加到所有按钮
btn19980930.addEventListener(MouseEvent.CLICK,showPopup);
btn19990224.addEventListener(MouseEvent.CLICK,showPopup);
BTN2000105.addEventListener(MouseEvent.CLICK,showPopup);
btn20050702.addEventListener(MouseEvent.CLICK,showPopup);
btn20060000.addEventListener(MouseEvent.CLICK,showPopup);
btn20060629.addEventListener(MouseEvent.CLICK,showPopup);
btn200720080000.addEventListener(MouseEvent.CLICK,showPopup);
btn20080229.addEventListener(MouseEvent.CLICK,showPopup);
BTN2009037.addEventListener(MouseEvent.CLICK,showPopup);
BTN2009 1209.addEventListener(MouseEvent.CLICK,showPopup);
BTN2101125.addEventListener(MouseEvent.CLICK,showPopup);
btn20110120.addEventListener(MouseEvent.CLICK,showPopup);
btn20110312.addEventListener(MouseEvent.CLICK,showPopup);
btn20110729.addEventListener(MouseEvent.CLICK,showPopup);
btn20110316.addEventListener(MouseEvent.CLICK,showPopup);
btn20110815.addEventListener(MouseEvent.CLICK,showPopup);
btn20110909.addEventListener(MouseEvent.CLICK,showPopup);
btn20110928.addEventListener(MouseEvent.CLICK,showPopup);
btn20111214.addEventListener(MouseEvent.CLICK,showPopup);
BTN2011010.addEventListener(MouseEvent.CLICK,showPopup);
变量initialX:Number=496;
功能显示弹出窗口(evt:MouseeEvent){
//找出哪个按钮被点击了
var buttonClicked=evt.currentTarget;
//未完成,我们需要使用时间线和宽度计算

if(stage.mouseX)根据研究调查hitTestObject,但仍然无法回答为什么使用localToG