0

菜鸟问题。好的,所以我试图在单独的 x 和 y 坐标处创建我的笔记(它是一个导入的图片)类的两个实例,然后我希望它们都向右移动。现在我编写了一个循环,循环工作正常,但它只保留最后一个创建的实例。这是我的代码。我非常感谢任何人可以提供的任何帮助。谢谢!

package 
{
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.utils.getDefinitionByName;

[Frame(factoryClass="Preloader")]
public class Main extends Sprite 
{
private var speed:int = 8;
[Embed(source="../lib/Dodgethis.jpg")]
public var Notes:Class;

public var numnotes:Number;

    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        stage.addEventListener(KeyboardEvent.KEY_DOWN, testevent);

        }

    private function testevent(e:Event = null):void {
        trace("testevent has run");
        appear(350, 250);
        //ap2(150, 150)
        //addEventListener(Event.ENTER_FRAME, loop, false, 0, true);    
    }

    private function appear(x:Number, y:Number) {
        var arr1:Array = new Array;
        numnotes = 4;

        for (var i = 0; i < numnotes; i++)
        {
            trace (i);
            var nbm:Bitmap = new Notes;

            if (i == 0) {
                this.x = 400;
                this.y = 400;
                addChild(nbm);
                trace ("1 should be different");
            } else {
                trace ("this is working");
                this.x = 150;
                this.y = 150;
                addChild(nbm);
                arr1.push(nbm);
4

1 回答 1

0

您创建了 4 个注释,但它们的位置是相同的点 (0,0)。

于 2013-09-05T01:40:16.070 回答