1

我想在动作脚本中将我的库中的一个对象放在我单击的舞台上。看起来很容易?对?完全消隐。任何帮助都会很棒:)到目前为止我的代码是:

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;
    }

}

}
4

1 回答 1

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);

    }
}

}
于 2013-03-07T20:29:05.300 回答