保存孩子的坐标位置

时间:2014-02-04 10:45:17

标签: actionscript-3

我有这些功能:

private function onEmptySpaceClicked(e:MouseEvent):void{

    var myVar = e.currentTarget.name;

    if (e.currentTarget.name == "ES1"){
    trace("click on one");
    clickPuzzles.click1 = true;
    }
    if (e.currentTarget.name == "ES2"){
    trace("click on two");
    clickPuzzles.click2 = true;
    }

public function buildIt(e:MouseEvent):void{
if (clickPuzzles.click1){
        test.x = e.currentTarget.x;
    test.y = e.currentTarget.y;
    test.visible = true;
}
}

构建函数由其他类调用。

一切正常,但是,是否可以将“onEmptySpaceClicked”函数中的e.currentTarget.x和y保存为值?

然后在我的buildIt函数中使用它?

喜欢:

private function onEmptySpaceClicked(e:MouseEvent):void{

    var myVar = e.currentTarget.name;

    if (e.currentTarget.name == "ES1"){
    trace("click on one");
        clickPuzzles.click1 = true
    e.currentTarget.x && e.currentTarget.y = valueOfEs1
    }
    if (e.currentTarget.name == "ES2"){
    trace("click on two");
        clickPuzzles.click2 = true
    e.currentTarget.x && e.currentTarget.y = valueOfEs2
    }

public function buildIt(e:MouseEvent):void{
if (clickPuzzles.click1){
        test.position = valueOfEs1
    test.visible = true;
}
if (clickPuzzles.click2){
        test.position = valueOfEs2
    test.visible = true;
}
}

感谢您的帮助


修改

谢谢你的建议。

这就是我的所作所为:

private function onEmptySpaceClicked(e:MouseEvent):void{
            trace("click on it neww");
var myVar = e.currentTarget.name;
            var valXes1;
            var valYes1;
            var valXes2;
            var valYes2;
        if (e.currentTarget.name == "ES1"){
            trace("il faut écouter emplacement");
            clickPuzzles.click1 = true;
            valXes1 = e.currentTarget.x;
                        valYes1 = e.currentTarget.y;
            trace(valXes1);
                    }
            if (e.currentTarget.name == "ES2"){
            trace("il faut écouter emplacement VARI");
            trace("puzzle2 est vrai");
            clickPuzzles.click2 = true;
            valXes2 = e.currentTarget.x;
                        valYes2 = e.currentTarget.y;
            trace(valXes2);
                    }
}


        public function buildIt(e:MouseEvent):void{
            var valXes1;
            var valYes1;
            var valXes2;
            var valYes2;
if (clickPuzzles.click1){
        test.x = valXes1
        test.y = valYes1
        test.visible = true;
}
if (clickPuzzles.click2){
    trace("puzzle2 is called");
        test.x = valXes2
        test.y = valYes2
        test.visible = true;
}
}

谜题2或1被很好地调用,但似乎valXes1和valXes2具有完全相同的值(valYes1和valYes2也是如此)。

我做错了什么?


编辑2

好的,所以我将emptyspace和emptyspace 2定位为:

            emptyspace .x = 0;
            emptyspace .y = 0;

                        emptyspace2.x = 50;
            emptyspace2.y = 50;

In the function onEmptySpaceClicked

if (e.currentTarget.name == "ES1"){
        trace("il faut écouter emplacement");
        clickPuzzles.click1 = true;
        valXes1 = e.currentTarget.x;
                valYes1 = e.currentTarget.y;
        trace(valXes1);
    }
if (e.currentTarget.name == "ES2"){
        trace("il faut écouter emplacement VARI");
        trace("puzzle2 est vrai");
        clickPuzzles.click2 = true;
        valXes2 = e.currentTarget.x;
                 valYes2 = e.currentTarget.y;
        trace(valXes2);

the trace(valXes1) is 0  and the trace(valXes2) is 50. 

所以它正在发挥作用。

,但 在这个功能:

public function buildIt(e:MouseEvent):void{
            var valXes1;
            var valYes1;
            var valXes2;
            var valYes2;
if (clickPuzzles.click1){
        test.x = valXes1
        test.y = valYes1
        test.visible = true;
}
if (clickPuzzles.click2){
    trace("puzzle2");
        test.x = valXes2
        test.y = valYes2
        test.visible = true;
}
}

迹线(“puzzle2”)显示(良好)但测试位置= at valYes1和valXes1
(所以“测试”动画片段位于错误的位置)

你知道什么是错的吗?

1 个答案:

答案 0 :(得分:0)

是,但不是

 e.currentTarget.x && e.currentTarget.y = valueOfEs1

你会

valXes1 = e.currentTarget.x;
valYes1 = e.currentTarget.y;

或创建一个Point对象并将x和y放在一个Point

import flash.geom.Point;

es1Point = new Point();
es2Point = new Point();

es1Point.x = e.currentTarget.x;
es1Point.y = e.currentTarget.y;
etc etc ...