AS3对象出现在点击鼠标在舞台上点击的位置

时间:2013-03-07 20:25:46

标签: actionscript-3 flash click mouseevent mouseclick-event

我想在actionscript中将一个对象放在我的库中,然后放到我点击的舞台上。好像很容易?对?完全消失。任何帮助都是极好的 :) 到目前为止我的代码是:

package code {

import flash.display.MovieClip;
import flash.events.MouseEvent;

public class Main extends MovieClip {

    public var redBox: Box = new Box(mouseX, mouseY);

    public function Main() {
        // constructor code
        stage.addEventListener(MouseEvent.CLICK, mouseClickEvent);
    }
    public function mouseClickEvent(e:MouseEvent):void {
        addChild(redBox);
    }
}

}

这是主要的,然后是盒子代码:

package code {

import flash.display.MovieClip;

public class Box extends MovieClip{

    public function Box(myX:Number, myY:Number) {
        // constructor code
        myX = x;
        myY = y;
    }

}

}

1 个答案:

答案 0 :(得分:3)

这样做:

package code {

import flash.display.MovieClip;
import flash.events.MouseEvent;

public class Main extends MovieClip {

    public var redBox: Box = new Box();

    public function Main() {
        // constructor code
        stage.addEventListener(MouseEvent.CLICK, mouseClickEvent);
    }
    public function mouseClickEvent(e:MouseEvent):void {
        redBox.x = stage.mouseX;
        redBox.y = stage.mouseY;
        addChild(redBox);

    }
}

}